Re: adding floating point



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 other
OK, 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!"
.



Relevant Pages

  • Re: adding floating point
    ... I was confusing the 'display' value ... inaccuracy with numerous places of introducing inaccuracy. ... And convert them to dollar for display ...
    (comp.lang.perl.misc)
  • Re: I need help with a login form too
    ... We do not care about what sex you are. ... I was having trouble with cut, copy, and paste too but I am ... > Then unload me part was confusing me. ... >>> display an appropriate message. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do i...
    ... I think you might be confusing two different things. ... table and use code in the form's BeforeUpdate event to set ... records can not use VBA code to display different values in ... This can be slow if the form is used to display a ...
    (microsoft.public.access.formscoding)
  • Re: I need help with a login form too
    ... I was having trouble with cut, copy, and paste too but I am ... "Login") ... Then unload me part was confusing me. ... >> display an appropriate message. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Hello Everyone
    ... It is confusing at first. ... Monitor "Generic Monitor" ... SubSection "Display" ...
    (alt.os.linux)