0
I have a form where brings BD and includes in the value of a text field the monetary value and with PHP (number_format) create the mask below for user view:
R$ 12,000,00
<input type="text" id="valorTotal" class="form-control" value="<?php echo number_format($valorTotal,2,',','.'); ?>" onchange="calcular()">
But I’m using Javascript for calculations and this field will be used. How would I remove this mask with Javascript making it look like this:
12000.00
Or without a thousand:
565.00
While doing the calculation and at the time of the presentation in another field the results, get back to with the mask:
<input type="text" name="ValorFinal" id="valorFinal" class="form-control" onchange="calcular()" required="required" readonly>
<script>
.....
document.getElementById('valorFinal').value = parseFloat(Math.abs(valorPP));
...
</script>
Hello Ricardo. Right. I used your code and it worked, but how would I make it so that in the visualization of the total value, you get to keep the mask? I tried to do this way, but it didn’t work. See:
retorno = "R$ " + valorT.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, "$1.");
– user24136
I did it this way, but it’s returning me this way: 1250,00 and not 1,250,00.
valorFinal = "R$ " + parseFloat(valorT).toFixed(2).replace('.',',');
– user24136
The answer was reformulated with the solution.
– Ricardo Pereira Dias
Perfect Ricardo. It worked!! Thank you very much!
– user24136