Good afternoon
I'm trying to represent a sum that the output value is in the formatting below:
$ 00.00
But I'm having difficulty with decimal place numbers,
Instead of the number being $ 15.10 it gets in the format $ 15,1
Can you help me?
Here is the code:
<html>
<head>
<script type="text/javascript">
function id( el ){
return document.getElementById( el );
}
function getMoney( el ){
var money = id( el ).value.replace(/[^0-9]/g,'');
return parseFloat( money );
}
function soma()
{
var total = (getMoney('campo1')+getMoney('campo2')+getMoney('campo3'))/100;
id('campo4').value = ('R$'+total).toString().replace('.', ',');
}
</script>
</head>
<body>
<form action="" method="">
<input name="campo1" id="campo1" value="10,00" /><br />
<input name="campo2" id="campo2" value="4,10" /><br />
<input name="campo3" id="campo3" value="1,00" /><br />
<input name="campo4" readonly="readonly" id="campo4" /><br />
<input type="button" onclick="soma()" value="Soma de Valores" />
</form>
</body>
</html>