I'm using this snippet to calculate the sum of two table cells.

var sum = 0;
$('.amount').each(function(){
    sum += parseFloat($(this).text());
});

$('.sum').text(sum);

But when the sum is for example 40.00 it displays as 40 and as picky as I am, i want it to display as 40.00. So... what to do?

Little (editable) demo: https://codepen.io/gentlemedia/pen/gGXJgR

I've found the answer myself :)

There is toFixed() method, so I had to add this to the sumvariable with the 2 as for the 2 decimals;

$('.sum').text(sum.toFixed(2));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.