Ralph Krausse writes:
>Can anyone explain why Value = 52 instead of 53?
>
>
>       float fValue = .53;
>       Int16 Value = (Int16)(fValue * (float)100);
>
>thanks

A C cast doesn't round a float to the nearest integer (most implementations
truncate towards 0).  If you want the nearest integer (53) then you might
try something more like:

   Int16 Value = (Int16)floor((fValue * 100.0) + 0.5);

Where floor() (and its source code) is in the MathLib library.


Ron Nicholson
HotPaw
   <http://www.hotpaw.com/rhn/hotpaw >

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to