Sprintf formatting a double value

I have one specific problem when converting values doubleto a string using sprintf()on UNIX.

For example, I have two values:

double a = 0.009984354523452;
double b = 0.01;

During the conversion, I use:

sprintf(somestringvar, "Double value : %.15f \n", a);
sprintf(diffstringvar, "Double value : %.15f \n", b);

to convert to string.

My problem is for 'a', the value prints correctly, but for the value of 'b', 0 is added at the end. Please provide me with a general way of representing "a" and "b" as exact values.

+5
source share
1 answer

b, printf 15 (%.15f), . - "", %g.


[ ]

, "". , ", ", . , , , , . , . printf() ostream , ( , , , , ), , double . .

, - . , MySQL NUMERIC DECIMAL , , , , .

+8

All Articles