You can check the decimal separator and remove it and everything after that:
function getDecimalSeparator() {
return /\./.test((1.1).toLocaleString())? '.' : ',';
}
function myToLocaleInteger(n) {
var re = new RegExp( '\\' + getDecimalSeparator() + '\\d+$');
return Math.round(n).toLocaleString().replace(re,'');
}
var n = 12345.99
console.log(n.toLocaleString() + ' : ' + myToLocaleInteger(n));
You will need to change the system settings in order to thoroughly test.
Edit
If you want to change the built-in toLocaleString function, try:
if (/\D/.test((1).toLocaleString())) {
Number.prototype.toLocaleString = (function() {
var _toLocale = Number.prototype.toLocaleString;
var _sep = /\./.test((1.1).toLocaleString())? '.' : ',';
var re = new RegExp( '\\' + _sep + '\\d+$');
return function() {
if (parseInt(this) == this) {
return _toLocale.call(this).replace(re,'');
}
return _toLocale.call(this);
}
}());
}
toLocaleString, .