• 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: CurrencyConverter not precise
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CurrencyConverter not precise


  • Subject: Re: CurrencyConverter not precise
  • From: Steffen Boerner <email@hidden>
  • Date: Tue, 12 Dec 2006 14:49:10 +0000

Thanks, thats what I found as well. I mean if you need accuracy in a financial application. There is no way around it unless you implement it yourself.

Am 12.12.2006 um 14:47 schrieb Jim Thomason:

It might be worthwhile and a good exercise to try converting it to
something more precise, either an NSDecimal (C structure) or
NSDecimalNumber (objc wrapper). They're not as much fun to work with
(float a = b + c vs NSDecimalNumber* a = [b decimalNumberbyAdding:c]),
but they're more accurate and should get rid of the errors.

-Jim.....

On 12/12/06, Steffen Boerner <email@hidden> wrote:
Cool thanks, that should get me started.
Am 08.12.2006 um 22:27 schrieb Sherm Pendley:

> On Dec 8, 2006, at 4:42 PM, Steffen Börner wrote:
>
>> Hi List,
>>
>> This is my first post here.
>> I just followed Apples tutorial "Building Currency Converter"
>>
>> http://developer.apple.com/documentation/Cocoa/Conceptual/
>> ObjCTutorial/chapter05/chapter_5_section_1.html#//apple_ref/doc/
>> uid/20002053-TPXREF101
>>
>> But when entering values with digits after the decimal sign the
>> calculated amount is not precise.
>> For example:
>> Exchange Rate: 3.22
>> Dollars to Convert: 10
>> Amount in other Currency:32,20000076293945
>
> In a nutshell, what you've found is a limitation of storing
> floating-point numbers in a binary format. Just as 1/3 cannot be
> exactly represented as a decimal number, there are numbers that
> cannot be exactly represented in binary.
>
> "What Every Computer Scientist Should Know About Floating-point
> Arithmetic":
>
> <http://docs.sun.com/source/806-3568/ncg_goldberg.html>
>
> sherm--
>
> Web Hosting by West Virginians, for West Virginians: http://wv- www.net
> Cocoa programming in Perl: http://camelbones.sourceforge.net
>
>


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >CurrencyConverter not precise (From: "\"Steffen Börner\"" <email@hidden>)
 >Re: CurrencyConverter not precise (From: Sherm Pendley <email@hidden>)
 >Re: CurrencyConverter not precise (From: Steffen Boerner <email@hidden>)
 >Re: CurrencyConverter not precise (From: "Jim Thomason" <email@hidden>)

  • Prev by Date: Re: CurrencyConverter not precise
  • Next by Date: Getting color attribute from NSFontPanel/NSFontManager
  • Previous by thread: Re: CurrencyConverter not precise
  • Next by thread: PDFKit: problem with PDFView goToDestination across PDFViews.
  • Index(es):
    • Date
    • Thread