Reputation: 869
I am drawing graph real-time and i have big numbers on axis like "200000000". It is hard to read it. I need it to be like "200kk" or anything else. Help?
Upvotes: 0
Views: 102
Reputation: 10388
function FormatterNum(num) {
if (num >= 1000000000) {
return (num / 1000000000).toFixed(1) + 'G';
}
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
}
if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num;
}
console.log(FormatterNum(6000));
reference How to format a number as 2.5K if a thousand or more, otherwise 900 in javascript?
Upvotes: 2