script Java non visualizza i decimali :(

guru of future

Nuovo Utente
Sono alle prese con questo script che pare funzionare ma non visualizza i decimali..

Codice:
<form>

<span class="givemegood">
<input type="checkbox" name="choice" value="150.00" onclick="clickCh(this)">+€ 150.00<br>
</span>

<span class="givemegood">
<input type="checkbox" name="choice" value="100.00" onclick="clickCh(this)">+€ 100.00<br>
</span>

<span class="givemegood">
<input type="checkbox" name="choice" value="4.150.00" onclick="clickCh(this)"> +€ 4.150.00<br>
</span>

<input id="total" type="text" name="total" value="0">
</form>
<script language="JavaScript" type="text/javascript">
var total = document.getElementById("total")
function clickCh(caller){
if(caller.checked){
add(caller)
} else {
subtract(caller)
}
}
function add(caller){	total.value = total.value*1 + caller.value*1}
function subtract(caller){	total.value = total.value*1 - caller.value*1}

</script>


Un piccolo aiutino ?


grazie infinite!!
 
ciao
prova a usare questa

Codice:
<script type="text/javascript">
function arrotonda (num, dec) {
	var div = Math.pow(10, dec);
	return Math.floor(num * div) / div;
}
//per test
alert(arrotonda(123.1234, 2));
</script>

output
 
Questo funziona:
HTML:
<!DOCTYPE html>
<html>
<body>
<form>

<span class="givemegood">
<input type="checkbox" name="choice" value="150.00" onclick="clickCh(this)">+€ 150.00<br>
</span>

<span class="givemegood">
<input type="checkbox" name="choice" value="100.00" onclick="clickCh(this)">+€ 100.00<br>
</span>

<span class="givemegood">
<input type="checkbox" name="choice" value="4150.00" onclick="clickCh(this)"> +€ 4.150.00<br>
</span>

<input id="total" type="text" name="total" value="0">
</form>
<script language="JavaScript" type="text/javascript">
var total = document.getElementById("total")
function clickCh(caller){
var ciao = parseFloat(total.value);
if(caller.checked){
add(caller)
} else {
subtract(caller)
}
}
function add(caller){
var sum= parseFloat(total.value) + parseFloat(caller.value);
total.value = sum.toFixed(2);
}
function subtract(caller){	
var sum = parseFloat(total.value) - parseFloat(caller.value);
total.value = sum.toFixed(2);
}

</script>
</body>
</html>
 

Discussioni simili