Re: adding floating point
- From: Amer Neely <perl4hire@xxxxxxxxxxxxxx>
- Date: Sat, 27 Jan 2007 14:14:42 -0500
Jürgen Exner wrote:
Amer Neely wrote:FAQ 'Why am I getting long decimals (eg, 19.9499999999999) ## instead of the numbers I should be getting (eg, 19.95)?' and otherOK, this is making more sense now. I was confusing the 'display' value
with the underlying real one (no pun intended). I've managed to get it
working by applying a rounding operation to each value along the way.
That is not a good idea. You are replacing one place of introducing inaccuracy with numerous places of introducing inaccuracy.
There are two options:
- Live with 'real' numbers being inaccurate
- use a different representation for your values, e.g. compute your prices in pennies instead of in dollars. And convert them to dollar for display only. Natural numbers can be represented accurately without approximation.
jue
I understand what you are saying, but I don't think this application requires the degree of accuracy you are considering. I only need to reflect what someone with a calculator, or using their head, would arrive at, applying standard rounding.
Now, if this were a financial investment application, I wouldn't even consider doing it myself.
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
.
- References:
- adding floating point
- From: Amer Neely
- Re: adding floating point
- From: Abigail
- Re: adding floating point
- From: Amer Neely
- Re: adding floating point
- From: Jürgen Exner
- adding floating point
- Prev by Date: Re: How can I convert a scalar to a range list ???
- Next by Date: FAQ 3.9 Is there a ctags for Perl?
- Previous by thread: Re: adding floating point
- Next by thread: Re: adding floating point
- Index(es):
Relevant Pages
|