Re: strings (dollar.cents) into floats
- From: Steve Holden <steve@xxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 12:06:49 -0400
sturlamolden wrote:
On 31 Aug, 02:12, Wildemar Wildenburger
<lasses_w...@xxxxxxxxxxxxxxxxx> wrote:
I've heard (ok, read) that several times now and I understand the
argument. But what use is there for floats, then? When is it OK to use them?
There are fractions that can be exactly represented by floats that
cannot be exactly represented by decimals.
Would you care to give an example?
There are fractions thatThat last sentence is patent nonsense, and completely untrue. Many satisfactory financial applications have been written using only floating-point arithmetic. Indeed I believe the accountant's Swiss army knife, the Excel spread***, uses floating-point numbers exclusively.
can be exactly represented by decimals that cannot be exactly
represented by floats.
Which one is better? Which do we prefer?
What a float cannot do is to represent a decimal fractional number
(e.g. 1.1) exactly. If we need that, we cannot use floats. A notable
example is monetary computations, it covers 99% of the use for decimal
numbers in computers. For this reason, we should never use floats to
add 10 cents to a dollar. The use of decimals for monetary
calculations is mandatory.
What you say about floating-point have speed advantages is true, but you go too far in claiming that decimal arithmetic is mandatory for monetary calculations. That's about as sensible as saying that base 12 and base 20 arithmetic units were required to calculate in pounds, shillings and pence.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
.
- References:
- strings (dollar.cents) into floats
- From: luca bertini
- Re: strings (dollar.cents) into floats
- From: Ben Finney
- Re: strings (dollar.cents) into floats
- From: Wildemar Wildenburger
- Re: strings (dollar.cents) into floats
- From: sturlamolden
- strings (dollar.cents) into floats
- Prev by Date: RE: win32com problem: more than one instance
- Next by Date: Re: So what exactly is a complex number?
- Previous by thread: Re: strings (dollar.cents) into floats
- Next by thread: Re: strings (dollar.cents) into floats
- Index(es):