sprintf problem

I have tried using "%f", "%2.2f", "%2f" and "%d".

None of those formats look good to me. %f and %d are OK.

If you want a floating point number with 2 decimal places, you need something like %6.2f,
where the first number ( 6 ) is the total number of characters and the second ( 2 ) is the number of digits after the decimal point.