method of getting around the rounding of floating and double precision numbers using printf().

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jul 15 14:46:08 AEST 1989


In article <4864 at ihlpe.ATT.COM> jec at ihlpe.ATT.COM (Morris) writes:
>I have tried all the usual stuff with the printf() statement [the
>%*.*f,7,2,variable_name  or %4.2f  or %.2  etc.,etc.] but none of
>these techniques were able to get around the rounding when printing
>these variables.

printf() is required to always print a properly-rounded representation
of its floating-point argument.  If you want to print some sort of
truncated quantity, you'll have to truncate it yourself before feeding
it to printf().  For example:	x = floor(x*100.0) / 100.0;



More information about the Comp.lang.c mailing list