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 16:53:10 +1000
On 15/08/2009, at 4:46 PM, Adil Saleem wrote:
On calling this, the variable aFloat in setMyvar method gets value
863.599976. I also tried giving it 6.600000 but still didn't work
correctly. I don't understand why is it changing the value. Why
doesn't it get 863.6 ?
This is a classic misunderstanding of floats. Look up "floating point
precision". Basically, a float is 32 bits - it can only represent 2^32
different values, not the infinity of numbers that exist. So quite
often certain values are rounded off, truncated or represent by
something "close". If you need exact values, use integers.
--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