AMM AMM - 1 year ago 45
C Question

How to use "%f" to populate a double value into a string with the right precision

I am trying to populate a string with a double value using a

like this:

sprintf(S, "%f", val);

But the precision is being cut off to six decimal places. I need about 10 decimal places for the precision.

How can that be achieved?

Answer Source


Width should include the decimal point.

%8.2 means 8 characters wide; 5 digits before the point and 2 after. One character is reserved for the point.

5 + 1 + 2 = 8

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download