how to shorten billion in javascript

Solutions on MaxInterview for how to shorten billion in javascript by the best coders in the world

showing results for - "how to shorten billion in javascript"
Ella
27 Jun 2019
1const formatCash = n => {
2  if (n < 1e3) return n;
3  if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K";
4  if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M";
5  if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B";
6  if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T";
7};
8
9console.log(formatCash(1235000));
Amy
01 May 2017
1const formatCash = n => {
2  if (n < 1e3) return n;
3  if (n >= 1e3) return +(n / 1e3).toFixed(1) + "K";
4};
5
6console.log(formatCash(2500));