Do you know if toFixed is a localized function?
I mean, will this:
var n = 100.67287; alert(n.toFixed(2));
show "100.67" on english US OS/browsers and "100,67" (with comma) on Italian OS/browsers? (Italian or any other local system that uses comma as decimal separator).
Thanks!
Late addition: with Number.toLocaleString()
now available on everything bar IE 10 & below, this works, albeit rather long-winded:
var n = 100.67287; console.log(n.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }));
Using undefined or 'default' for the language code will use the browser default language to format the number.
See developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString for full details.
If you're free to extend the Number prototype, you could defined Number.toLocaleFixed()
.
No, this will always return a point. The ECMA 262-spec [15.7.4.5] states it should be a point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With