Answers for "how to shorten billion in javascript"

0

how to shorten billion in javascript

const formatCash = n => {
  if (n < 1e3) return n;
  if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K";
  if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M";
  if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B";
  if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T";
};

console.log(formatCash(1235000));
Posted by: Guest on June-13-2021
0

how to shorten billion in javascript

const formatCash = n => {
  if (n < 1e3) return n;
  if (n >= 1e3) return +(n / 1e3).toFixed(1) + "K";
};

console.log(formatCash(2500));
Posted by: Guest on June-13-2021

Code answers related to "how to shorten billion in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language