# Thread: Help with a percentage

1. ## Help with a percentage

I am having a problem with finding percentage. When displaying output from math problems i need: # complete, Right, Wrong, and percentage right. All but percentage comes out correct. If all problems are correct it shows 100% anything else is 0%. What am I doing wrong.

2. You only get a floating point result if your operands to the division operator are floats themselves[1]. So:

Code:
`(((float)AddCountRight) / ((float)TotalAddProb) *100.0f)`
See if that works. It forces the operation to use floating point numbers, which will result in a correct output. You see, when all is right, you get the quotient between two equal integers, which is 1. If AddCountRight decreases, it is always <1. Since the operation is based with integers, that value is truncated, so any 0.xxxxx value will become 0. If you force the operation to be float based, you'll get your results.

[1] Actually, I am not sure if it is enough to have a float operand, so I always play safe and have both of them be treated as floats. Someone please correct me about this issue or advise a better technique.

3. ## Thanks

Thanks that worked I understand where I went wrong. I am new to programming and this board has been invaluable. Thanks again..

4. Only one of the operands need to be a floating number. You can also multiply by 1.0 to convert it to a floating point number without the use of casts.
So long as the first expressions is a floating point, then the entire result will be a floating point.