Skip to content

Instantly share code, notes, and snippets.

@sidisinsane
Last active April 29, 2016 07:52
Show Gist options
  • Save sidisinsane/c1837dbc21edad277957c00903e00590 to your computer and use it in GitHub Desktop.
Save sidisinsane/c1837dbc21edad277957c00903e00590 to your computer and use it in GitHub Desktop.
Revokes formatting previously applied by ‘Intl.NumberFormat‘
// ---
// Revokes formatting previously applied by ‘Intl.NumberFormat‘
//
// Usage:
// '123.456,78'.revokeIntlNumberFormat('de-DE');
// Result:
// 123456.78
// ---
Object.defineProperty(Object.prototype, 'revokeIntlNumberFormat', {
value: function(locale) {
if (typeof Intl.NumberFormat === 'function' && typeof locale !== 'undefined') {
var tsdSep = new Intl.NumberFormat(locale, {
useGrouping: true,
maximumFractionDigits: 0
}).format(1111).replace(/[0-9]/g, '');
var decSep = new Intl.NumberFormat(locale, {
minimumFractionDigits: 1
}).format(1.1).replace(/[0-9]/g, '');
return Number(this.replace(tsdSep, '').replace(decSep, '.'));
} else {
return this;
}
},
enumerable: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment