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
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