Javascript toFixed localized?
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 sadly, there is no real solution in pure jQuery/JavaScript. You'll need Globalize. The problem is that both toFixed() and toLocaleString() take a number and return a string. So you can never use them together. :( If you call foo.toFixed(2).toLocaleString() you won't get the localization (i.e. '1.234' in en should be '1,234' in fr) because its working on the result of toFixed() which is a string, not a number. :(