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. 
 
 
 

--- On Fri, 8/14/09, Graham Cox <graham....@bigpond.com> wrote:


From: Graham Cox <graham....@bigpond.com>
Subject: Re: Problem with Float type variable
To: "Adil Saleem" <adilsalee...@yahoo.com>
Cc: cocoa-dev@lists.apple.com
Date: Friday, August 14, 2009, 11:53 PM



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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to