• 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: inconsistent float behaviour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inconsistent float behaviour


  • Subject: Re: inconsistent float behaviour
  • From: "Michael Ash" <email@hidden>
  • Date: Fri, 10 Oct 2008 13:16:39 -0400

On Fri, Oct 10, 2008 at 7:04 AM, Steven Hamilton <email@hidden> wrote:
> The float calculation is exactly 2
> decimal places

This is unlikely. There are very few numbers with two decimal places
which can be perfectly represented in floating-point numbers. (Those
would be numbers with fractional values that can be composed from
powers of two, i.e. 0.25, 0.5, and 0.75.)

You'll probably want to read this:

http://docs.sun.com/source/806-3568/ncg_goldberg.html

And then stop using floating point math for anything which you require
to produce an exact result.

For money, the best thing to do is to simply perform calculations in
cents using integers, then divide by 100 for display purposes only.

Mike
_______________________________________________

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: 
 >inconsistent float behaviour (From: Steven Hamilton <email@hidden>)

  • Prev by Date: Re: inconsistent float behaviour
  • Next by Date: Re: Finder Crashes on File Open
  • Previous by thread: Re: inconsistent float behaviour
  • Next by thread: Re: inconsistent float behaviour
  • Index(es):
    • Date
    • Thread