[comp.lang.c] Rounding in C

RHMCSUPV@MIAMIU.BITNET (Douglas M. MacFarlane) (09/05/90)

Thanks to all who posted responses and e-mailed me directly on my
assinging values to type float question.  They were most appreciated.
 
Microsoft C ver 5.1 required an explicit cast (ugh or yuk from some
of you) i.e.:
 
fValue = (float) 35 ;
 
to remove the data conversion warning.
 
Next question:  Rounding
 
fPrice = 1.35 ;
 
fSpending = 10000 * fPrice ;
 
printf ( "Spending is:  %f", fSpending ) ;
 
produces the output 13499.9997  instead of 13500
 
I seem to recall that these problems are inherent to computing, but
a rounding function would do the trick.  Has anyone written a
RoundAFloat function that accepts a floating point value and the
number of decimal places to round to ( 2 for round to 2 decimal places,
-2 to round to the hundreds, etc.)?
 
If so, could you send it to me, or post.
 
 
Thanks
 
Doug MacFarlane
RHMCSUPV at miamiu.acs.muohio.edu