Can someone please help!!
This should be simple.
I am trying to add 92.85 and 2.95 together using javascript but the answer I
get is 188.64999999999998 (this should not be posible.) Can someone tell
me what the hell is going on and howe to get round this.
(The .htm source code I am using is below)
Cheers!!
Dave!!
Adding
language="javascript">
Comments
:
: This should be simple.
: I am trying to add 92.85 and 2.95 together using javascript but the answer I
: get is 188.64999999999998 (this should not be posible.) Can someone tell
: me what the hell is going on and howe to get round this.
: (The .htm source code I am using is below)
:
: Cheers!!
:
: Dave!!
:
:
:
:
: Adding
:
: language="javascript">
:
:
:
:
:
:
This is a very stupid thing in javascript (what I think)...
Anyway I got your solution here:
<script language="javascript">
var nNum1, nNum2, nResult
nNum1 = 95.8;
nNum2 = 92.85;
nResult = nNum1 + nNum2;
alert(parseInt(nResult));
</script>
Just put in the parseInt() in the alert then it will work fine...