I'm trying to give the outcome of this script 2 decimals. They all actually already have 2 decimals, but when I add the last 2 together (35.75 + 16.06), I get €51.629999999999995 as the output.
Here is my script;
<!DOCTYPE html>
<html>
<head>
<script>
function bereken() {
var total = 0;
if (document.forms[0].boek1.checked) {
total += 27.74;
}
if (document.forms[0].boek2.checked) {
total += 26.13;
}
if (document.forms[0].boek3.checked) {
total += 35.57;
}
if (document.forms[0].boek4.checked) {
total += 16.06;
}
totalP = "€" + total
document.forms[0].total.value = totalP;
}
</script>
</head>
<body>
<form>
<input type="checkbox" name="boek1">Boek 1<br>
<input type="checkbox" name="boek2">Boek 2<br>
<input type="checkbox" name="boek3">Boek 3<br>
<input type="checkbox" name="boek4">Boek 4<br>
<div><input type="button" value="Totaal" onclick="bereken()" /><br><br>
<input type="text" value="€" name="total" size="5" />
</form>
</body>
Does any of you know what I did wrong?