jec@ihlpe.ATT.COM (Morris) (07/12/89)
The subject of the inaccuracies caused by rounding has probably been brought up many times in this news group and I apoligize if it has. I need to know of any routines that are currently being used to get around C's rounding of foating point and double precision numbers when using the printf() routine from the stdio.h header file. I have talked to many comrades but none of them can remember how the routine went. 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. The variables have been declared to be of type float and of type double but to no avail. I would appreciate any responses either by replying directly to this posting or to my email address ...att!ihcae!jec. Thanx in advance.
gwyn@smoke.BRL.MIL (Doug Gwyn) (07/15/89)
In article <4864@ihlpe.ATT.COM> jec@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;