• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem with Float type variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Problem with Float type variable (From: Adil Saleem <email@hidden>)

  • Prev by Date: Re: Problem with Float type variable
  • Next by Date: Re: Title bar highlighting behavior
  • Previous by thread: Re: Problem with Float type variable
  • Next by thread: Re: Problem with Float type variable
  • Index(es):
    • Date
    • Thread