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 " 00,23
" discount, it shows the percentage value of "0.22999999999999998"% or if I inform you a discount percentage of " 03,4
"% it shows me the real discount of " 3,4000000000000004
" R $, I only want 2 decimal places after the comma.