randomhero69
Technical User
I builded a little script that can calculate the difference of two prices.. The values should have decimals. When I try my function, it returns 479.9600000000003 instead of 479.96 ... Any ideas? Here's the script :
===========================================================
<script language="JavaScript">
var totalPrice = 1139.45;
var articlePrice = 659.49;
function calculateDifference() {
totalPrice = totalPrice - articlePrice;
alert(totalPrice);
}
</script>
<form action="" method="post" name="monForm" id="monForm">
(1139.45 - 659.49)<br>
<br>
I think the answer should be 479.96 but...<br>
<br>
<input type="submit" name="btn" value="Calculate difference" onclick="calculateDifference()">
</form>
===========================================================
Thanks a lot!
===========================================================
<script language="JavaScript">
var totalPrice = 1139.45;
var articlePrice = 659.49;
function calculateDifference() {
totalPrice = totalPrice - articlePrice;
alert(totalPrice);
}
</script>
<form action="" method="post" name="monForm" id="monForm">
(1139.45 - 659.49)<br>
<br>
I think the answer should be 479.96 but...<br>
<br>
<input type="submit" name="btn" value="Calculate difference" onclick="calculateDifference()">
</form>
===========================================================
Thanks a lot!