Internationalization and localization of javascript code isn't particularly easy. The
parseFloat
method doesn't handle different culture settings; it always assumes that
"."
is the decimal separator, and
","
is the thousands separator.
The options you're passing to
the toLocaleString
method[
^] are only supported in modern browsers - Chrome 24+, Firefox 29+, IE11+, and Opera 15+. They are
not supported in Safari.
The jQuery Foundation have developed a well-supported, open-source library to handle these problems:
https://github.com/jquery/globalize[
^]
Using the library will let you parse and format numbers, currency, dates, times, and other common items using your preferred locale. For example:
var number = Globalize("de-DE").parseNumber(this.value);
this.value = Globalize("de-DE").formatCurrency(number, "EUR", { maximumFractionDigits: 2 });