Re: 1.45 x 1 = 1.450000047683716 ? :: CurrencyConverter
Re: 1.45 x 1 = 1.450000047683716 ? :: CurrencyConverter
- Subject: Re: 1.45 x 1 = 1.450000047683716 ? :: CurrencyConverter
- From: Nicko van Someren <email@hidden>
- Date: Mon, 17 Jan 2005 08:44:10 +0000
On 17 Jan 2005, at 6:44, NOYFB wrote:
When I enter
1.4 x 1 = 1.450000047683716 should be 1.45
1.1 x x = 1.100000023841858 Should be 1.1
1 x 1 = 1 Ok.
I do not think this is normal or maybe it is and there is extremely
good explanation to use setFloatingPointFormat.
Pleas confirm If it's a bug or that I have to specify some sort of
flag/option?
The binary expansions of both 1.45 and 1.1 are infinitely long; 1.45
decimal is binary 1.0111[0011]* (the last four digits recur
indefinitely) and 1.1 decimal has the binary value 1.0[0011]*. Since
the accurate floating point representation is infinitely long and the
storage of the number is finite we loose accuracy.
The best way to deal with this in practice is to adjust your floating
point printout format to limit the number of significant digits.
Cheers,
Nicko
_______________________________________________
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