Re: inconsistent float behaviour
Re: inconsistent float behaviour
- Subject: Re: inconsistent float behaviour
- From: "Michael Ash" <email@hidden>
- Date: Fri, 10 Oct 2008 13:16:39 -0400
On Fri, Oct 10, 2008 at 7:04 AM, Steven Hamilton <email@hidden> wrote:
> The float calculation is exactly 2
> decimal places
This is unlikely. There are very few numbers with two decimal places
which can be perfectly represented in floating-point numbers. (Those
would be numbers with fractional values that can be composed from
powers of two, i.e. 0.25, 0.5, and 0.75.)
You'll probably want to read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
And then stop using floating point math for anything which you require
to produce an exact result.
For money, the best thing to do is to simply perform calculations in
cents using integers, then divide by 100 for display purposes only.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden