(lack of) precision

  • Thread starter Pjotr Wedersteers
  • Start date
P

Pjotr Wedersteers

I have a form form1 where user enters two values input1 and input2.
Then a function addValues () is called:
function addValues()
{
var var1 = parseFloat(document.form1.input1.value)
var var2 = parseFloat(document.form1.input2.value)
document.form1.output.value = var1 + var2
}

When I enter 4.0001 and 1.0001 the result in my script is not 5.0002 but
5.0001999999999995
Of course this is sufficiently precise in most uses, or can be rounded off.
Still I have seen no other language where rounding errors are so prominent
after one simple addition.
Are these errors a result of parseFloat() ? Am I missing something crucial ?
Is there an easy way to increase the precision ?

TIA
Pjotr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top