[ACCEPTED]-Javascript Number formatting min/max decimals-numbers

Accepted answer
Score: 23

New 2016 solution

value.toLocaleString('en-US', {
    minimumFractionDigits: 2,
    maximumFractionDigits: 4

Do not forget to include polyfill.

Old 2011 solution

To format a part, after 2 decimal point you can use this:

value.toFixed(4).replace(/0{0,2}$/, "");

And for part 1 before decimal point: How to write this JS function in best(smartest) way?

Score: 0

You're doing it wrong.

54433.6559943.toFixed(4) will round to 4 places. You 2 then have to trim off up to two trailing 1 zeroes.

More Related questions