I have the following function that automatically adds the commas to an American numerical expression which is some way of localisation. I need a minor change to this function.
if I have 160 * 54.08 = 8.652,8 as input to the function what can I do to show the output as 8.652,80
with two decimal places? Right now the function outputs as 8.652.8
function Numberformat(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? ',' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + '.' + '$2');
}
return x1 + x2;
}