Currently output 1844.6304
desired output - comma thousands trim after dot ( no rounding )
1,844
I was looking some time on forums and can't find a solution to solve both cases.
Currently output 1844.6304
desired output - comma thousands trim after dot ( no rounding )
1,844
I was looking some time on forums and can't find a solution to solve both cases.
Its even simpler like this
var n = 1844.6304,
s = Math.floor(n).toLocaleString();
console.log(s); //"1,844"
alert(s);
Try this:
function intWithCommas(x) {
return Math.floor(x).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
Example:
> intWithCommas(1844.6304)
'1,844'
Try this:
function toCommaInteger(number){
var result = "" + ~~number;
var length = result.length;
var limit = result[0] === "-" ? 1 : 0;
for(var i = length-3; i > limit; i-=3 ){
result = result.substring(0,i) + "," + result.substring(i,length);
length++;
}
return result;
}
toCommaInteger(123589.85315) => 123,589
toCommaInteger(-1289.15315) => -1,289
toCommaInteger(5) => 5