1
How do I show only 2 decimal places after the comma.
I have the following script:
<script>
function DescontoPorcentagem() {
var bruto = $("#tot_bruto").val();
var porcentagem = $("#Tot_desc_prc").val();
var real = $("#Tot_desc_vlr").val();
var total;
total = parseFloat((parseFloat(porcentagem) / 100) * parseFloat(bruto));
$("#Tot_desc_vlr").val(parseFloat(total));
total = parseFloat(bruto) - parseFloat(total);
$("#tot_liquido").val(parseFloat(total));
}
function DescontoReal() {
var bruto = $("#tot_bruto").val();
var porcentagem = $("#Tot_desc_prc").val();
var real = $("#Tot_desc_vlr").val();
var total;
total = parseFloat(bruto) - parseFloat(real)
$("#tot_liquido").val(parseFloat(total));
total = (real / bruto) * 100
$("#Tot_desc_prc").val(total);
}
</script>
If I have a value in the field "tot_bruto
" of 100, and give a discount of "00,23
"R$ it shows the value of the percentage of "0,22999999999999998"% or if I report a discount in percentage of "03,4
"% he shows me the real discount of "3,4000000000000004
"R$, I just want it to appear 2 decimal places after the comma.
Tries with
.toFixed(2)
.– Sam