[ACCEPTED]-Javascript Number formatting min/max decimals-numbers
Accepted answer
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?
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.