ParseFloat Precision.
Jul 23, 2005
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?
View 1 Replies
May 17, 2011
here is the code, it is supposed to calcualte the total of the books and display them but when displayed all i get is NAN (only works in ie). This is part of my course work .
<html>
<head>
<title>Arrays</title>[code]....
View 2 Replies
View Related
May 17, 2011
Here is the code, it is supposed to calculate the total of the books and display them but when displayed all i get is NAN (only works in ie). code....
View 2 Replies
View Related
Apr 27, 2005
Multiplication of numbers do not give a right value
For eg.
9090909090909.8 * 100 = 909090909090980.1
Why is it so? Is there a way to save the loss of precision.
Actually i want numbers to be rouned to the nearest 2 decimal places only
so Math.round(9090909090909.8 * 100) / 100 is the formula i am using, and hence the multiplication with 100 was required. Since the multiplication give a faulty value, the final result is also not as expected.
I was suprised with the fact
alert(9090909090909.8112) alerts only "9090909090909.8"
View 3 Replies
View Related
Jan 29, 2009
highprecisioncalculator in java script
View 1 Replies
View Related
Oct 1, 2009
I am trying to set up a toggle to allow users to show more precision when a user clicks a button. I have a function high() that doesn't do anything when it is called. I am fairly new to jQuery so I am not to familiar with the syntax.
View 2 Replies
View Related