Subject: RE: double problem
From: "dilek.ozgu" <[EMAIL PROTECTED]>
Date: Wed, 21 Jan 2004 11:40:22 +0200
X-Message-Number: 6

thanks
i try but

xx = (double) 816 / (double) 10 or

xx = 816.00 / 10.00

its result 81.599999 ???

This is normal behavior for floating point arithmetic.


When people post to this forum saying they want a precise number with two decimal places, then they are usually referring to currency.
If this is your case, then hold your currency in an Int32 as cents (or whatever), then you can do integer arithmetic.


   Int32 x, a, b;
   a=81600;
   b= 10;
// first divide
   x=a/b;
// then round to nearest
   if ((a%b)>=(b>>1))  x++;

Notes:
1) This is all normal programming stuff and nothing specific to Palm OS.
2) Int32 provides for 9 signed digits.  For more, use 'long long'
3) This simple rounding logic doesn't handle negative numbers !!!!
4) Integer arithmetic is faster than floating point.

Roger Stringer
Marietta Systems, Inc.  (www.mariettasystems.com)


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

Reply via email to