469,342 Members | 5,602 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

(lack of) precision

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
Jul 23 '05 #1
1 1122
On Sun, 7 Nov 2004 12:50:00 +0100, Pjotr Wedersteers wrote:
When I enter 4.0001 and 1.0001 the result in my script is not 5.0002 but
5.0001999999999995
<http://www.jibbering.com/faq/#FAQ4_7>
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.
Like what languages?

Here's the result for Java..
value1: 4.0001
value2: 1.0001
value1 + 2: 5.0001999999999995
Are these errors a result of parseFloat() ? Am I missing something crucial ?


See the link above.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Brian van den Broek | last post: by
5 posts views Thread by DAVID SCHULMAN | last post: by
3 posts views Thread by Madan | last post: by
6 posts views Thread by R.Biloti | last post: by
2 posts views Thread by rupert | last post: by
9 posts views Thread by asdf | last post: by
10 posts views Thread by Bo Yang | last post: by
reply views Thread by Charles Coldwell | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.