Display monetary values in a simple way [duplicate]

0

Good morning!

What would be the plus simple way of displaying monetary values with Javascript? I was able to limit the decimal places using .toFixed(2) . But the whole part gets more or less like this 10510.20 I wanted it to be 10.520,20 . Any suggestion?

    
asked by anonymous 22.08.2017 / 15:18

1 answer

1

Use this function has always given me a huge way for this problem:

function format_num(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
    
22.08.2017 / 15:20