Forums

show 2 decimal value

Mgringo 16 Dec, 2013
Hi,

Is there an easy way to show 2 decimal behind a comma ... like 2,50 instead of 2,5
function pricefunc(){
    var ant1 = document.getElementById('aantal_volwassen').value,
        ant2 = document.getElementById('aantal_kind').value;
    
    var const1 = document.getElementById('prijs_volwassen').value,
        const2 = document.getElementById('prijs_kind').value;
    
    var sum1 = document.getElementById('totaal_prijs_volwassen'),
        sum2 = document.getElementById('totaal_prijs_kind');
    
    var total = document.getElementById('totaal_prijs_kind');
    
   sum1 = sum1.value = ant1 * const1;
   sum2 = sum2.value = ant2 * const2;
    
  document.getElementById('totaal_bedrag').value = sum1  + sum2;



};


Tnx! Gringo
GreyHead 16 Dec, 2013
Hi Mgringi,

Please try replacing:
document.getElementById('totaal_bedrag').value = sum1  + sum2;
with
var sum = sum1  + sum2;
$('totaal_bedrag').value = sum.format({
  decimal: ',',
  decimals: 2
});

Bob
Mgringo 16 Dec, 2013
Hi Bob,

Thx for your quick respons ... but ... No doesn't work😟
Mgringo 16 Dec, 2013
Hi Bob ... I'm sorry it does work🙂

Tnx very much!
This topic is locked and no more replies can be posted.