Guenther Sohler:
I also tried %g:
int main(void)
{
printf("%g\n",-2158475*0.001);
}
which results in
-2158.47
one digit is missed! this is a killing issue for me!
Well, then it's time for you to read the appropriate part
of the standard.
ISO/IEC 9899:TC2
7.19.6.1#8
g,G A double argument representing a floating-point number is converted
in style f or e (or in style F or E in the case of a G conversion
specifier), depending on the value converted and the precision.
Let P equal the precision if nonzero, 6 if the precision is omitted,
or 1 if the precision is zero. Then, if a conversion with style E
would have an exponent of X:
- if P > X ≥ -4, the conversion is with style f (or F) and
precision P - (X + 1).
- otherwise, the conversion is with style e (or E) and precision P - 1.
Finally, unless the # flag is used, any trailing zeros are removed from
the fractional portion of the result and the decimal-point character is
removed if there is no fractional portion remaining.
So try %.9g or something like that.
how can i have the proper value displayed in all cases ?
This could be difficult depending on the meaning of proper.
Jirka