Sorry, i already asked a simular question about this topic yesterday, but i still couldn’t figure it out.
I have a form that calculates prices, but sometimes i get more than tow positions behind the comma. I know how i can round, but i don’t know how i can round to two positions behind the comma!?
If you choose a one in all three menus in the following code you will see my problem(the result is: 389.40000000000003).
<html>
<head>
<script language=”JavaScript” type=”text/JavaScript”>
function price() {
var two = parseFloat(window.document.form1.menu1.value);
var three = parseFloat(window.document.form1.menu2.value);
var four = parseFloat(window.document.form1.menu3.value);
var five = two + three + four;
window.document.form1.textfield.value = five;
}
</script>
</head>
<body>
<form name=”form1″>
<select name=”menu1″ size=”1″ onChange=”price()”>
<option value=”0″>0</option>
<option value=”129.80″>1</option>
</select>
<br>
<select name=”menu2″ size=”1″ onChange=”price()”>
<option value=”0″>0</option>
<option value=”129.80″>1</option>
</select>
<br>
<select name=”menu3″ size=”1″ onChange=”price()”>
<option value=”0″>0</option>
<option value=”129.80″>1</option>
</select>
<input type=”text” name=”textfield”>
</form>
<br>
</body>
</html>