我正在实时绘制图形,我在轴上有大数字,如" 200000000"。很难读懂它。我需要它像" 200kk"或其他任何东西。帮助
答案 0 :(得分:2)
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));
参考How to format a number as 2.5K if a thousand or more, otherwise 900 in javascript?