# Thread: Loss of Precision Question.

1. ## Loss of Precision Question.

Hey, Im having a bit of a problem printing this data.
I am trying to divide two integers and print out a float.
For example:

Code:
```sum = 521;
printf(" a = %.1f\n", (float)(sum/2));
printf(" b = %.2f\n", (float)(sum/100));```
I want to get:
a = 260.5
b = 5.21%

a = 260.0
b = 5.00

Also , how do i get that percentage sign in there after the number?
thanks alot.

2. cast sum to a float, not the result (which is still being done in integer math).

3. Yeah, what he said.

I assume sum is an int. So that means any calculations such as sum/2 are integer math including the result. You need to either declare sum as a float, or force it to be float prior to the division:
Code:
`(float)sum / 2`
or better still make the constant a floating point value:
Code:
`sum / 2.0`
Also, you said you wanted the output to look like b = 5.21&#37;
Code:
`printf(" b = %.2f%%\n", ...`
NOTE the double '%' to print out a single '%'. That way it's not mistaken for another format specifier.