format number K

PHOTO EMBED

Sun Nov 21 2021 03:12:30 GMT+0000 (Coordinated Universal Time)

Saved by @caberg2000 #javascript

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

console.log(formatCash(2500));
content_copyCOPY

https://stackoverflow.com/questions/9461621/format-a-number-as-2-5k-if-a-thousand-or-more-otherwise-900