0

I am creating a calculator and need guidance on adding thousand separators to a whole number.

//logic  
    var portVal = 100000000;
    var rateUSD = 1.3654;        
    var sustPortBase = 22;
    var avgPortBase = 66;
    var sustPortCarb = (portVal*rateUSD/1000000)*sustPortBase;
    var avgPortCarb = (portVal*rateUSD/1000000)*avgPortBase;
    var diff = avgPortCarb - sustPortCarb;
    var nbHomes = diff * 0.115;
    var nbCars = diff * 0.216;
    var nbTrees = diff * 16.5;
    var nbPlanes = diff * 0.833359;
    var avgPortCarbRound = avgPortCarb.toFixed();
    var sustPortCarbRound = sustPortCarb.toFixed();

console.log("Cars:"+(nbCars).toFixed());
console.log("Cars Decimals:"+(nbCars).toLocaleString('en'))

Outputs:

Cars:1298 
Cars Decimals:1,297.676

I would like to keep only thousand seperators but nothing after the (dot.) i.e. 1,297

https://jsfiddle.net/ge5oj2xk/1/

David Garcia
  • 3,056
  • 18
  • 55
  • 90

1 Answers1

1

Try using Math.floor function.

console.log("Cars Decimals:"+Math.floor(nbCars).toLocaleString('en'))