> On Wed, 2002-06-05 at 10:56, Johnathan Smith wrote: > > Can someone please help me I am getting a number like > > "19.47582" and I only need "19.47"
--- Dave Carrigan <[EMAIL PROTECTED]> wrote: > Floating point arithmetic is not able to represent an > infinite number of real numbers in a finite number of bits, > which can result in inexact calculations. If you're planning > to represent currency and require exact decimals, you should > use integers. If, OTOH, you really want to know how to round off a floating point number to 2 decimal places as your subject line suggests, that is something that you should have learned from your first programming class (or book). In case you missed that, here is what to do. Int32 i; float f = 19.47582; i = (f + 0.005) * 100.00; // i will be 1948 f = (float)i / 100.00; // f will be 19.48000 or, to do it in 1 line: f = (float)((Int32)((f + 0.005) * 100)) / 100.00; This will still have the precision problem Dave mentioned, but it will "round" the float to 2 decimal places. And, if you want to know how to *display* "19.48" instead of "19.48000", then, once again, you'd be better off using an integer instead of a float because the StrPrintF() function in the Palm API doesn't know how to deal with floats. Or, you can search the archives for code that formats floating point numbers. __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
