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

Re: Float behaviour


  • Subject: Re: Float behaviour
  • From: Brian Smith <email@hidden>
  • Date: Tue, 23 Aug 2005 08:33:06 +0800

Yes, they really need a cocoa class for this maybe they could call it NSDecimalNumber;o)

Brian

On Aug 23, 2005, at 1:59 AM, ObjM2 wrote:


On Aug 23, 2005, at 2:19 AM, Richard Gray wrote:


If I were to convert $1 at an exchange rate of 1.2, I'd expect to get
1.2 units of the new currency yes? According to my currency converter
however, 1 x 1.2 = 1.200000047683716


Can someone explain this behaviour to me and how to avoid it?


You'll need a BCD library (BCD = binary coded decimals => no rounding errors)


http://en.wikipedia.org/wiki/Binary-coded_decimal

However, there is no support for BCDs amongst the generally available C libraries, so you'll have to roll your own or use a different language. COBOL uses BCDs by default. p1 Modula-2 for the Mac has built-in BCD support, but no Cocoa support and it's not free either.

ObjM2 when finished, will also have BCDs built-in, but that won't help you right now.

It shouldn't be all too difficult to write a Cocoa class for BCDs though.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Float behaviour (From: Richard Gray <email@hidden>)
 >Re: Float behaviour (From: ObjM2 <email@hidden>)

  • Prev by Date: Re: NSArrayController selection issue
  • Next by Date: Re: addObject failing
  • Previous by thread: Re: Float behaviour
  • Next by thread: Re: Float behaviour
  • Index(es):
    • Date
    • Thread