• 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 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


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

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