3
Good afternoon
I am trying to represent a sum that the output value is in the formatting below:
R$ 00,00
But I’m having trouble with decimal numbers,
instead of the number staying R$ 15,10 it gets in formatting R$ 15,1
Can you help me?
Below is the progress of 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>