Re: Problem with Float type variable
Re: Problem with Float type variable
- Subject: Re: Problem with Float type variable
- From: Graham Cox <email@hidden>
- Date: Sat, 15 Aug 2009 17:08:32 +1000
On 15/08/2009, at 5:01 PM, Adil Saleem wrote:
But why would it round 863.6 ? I mean there is only 1 digit after
the decimal. It should not have the range problem with a value this
small.
It's got nothing to do with how it is written in decimal - it only
matters what its binary representation is, and that is always 32 bits
(or 64 if double precision or on a 64-bit machine).
Start here, particularly the section starting "Accuracy Problems":
http://en.wikipedia.org/wiki/Floating_point
Note, there is a class called NSDecimalNumber which can help with this
sort of problem, if you can't live with the vagueness of float.
--Graham
_______________________________________________
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