If you can handle accuracy to two decimal places, than this code should work
(untested) because integer division is more precise:

double weight;
UInt32 temp = (UInt32)(weight * 100);

temp /= 220; /* 220 = 2.2 x 100 */
weight = temp / 100.0;

Cheers,
James.

> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Denis
> Faivre
> Sent: Monday, 03 September 2001 16:50
> To: Palm Developer Forum
> Subject: Re: Weird math problem
>
>
> > double weight; //the value from the weight text field in pounds
> >
> > weight = weight / 2.2; //weight in kilograms
> >
> > The above works fine in every instance I have tested it against except
> > when weight is equal to 220. When weight = 220, the result is
> 99.1 and not
> > 200.
>
>
> Just tried the code you gave, and got 99.999...9, which sounds good (BTW,
> the right result is 100, not 200).
>
> I used PalmOS 4.0, CodeWarrior 7.
>
> -- Denis Faivre - [EMAIL PROTECTED]
> -- Ablivio - http://www.ablivio.com
>
>
>
> --
> For information on using the Palm Developer Forums, or to
> unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
>
>


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

Reply via email to