3 ms·
Overkill. KISS. n counts moving the decimal left 3 places until there are <=3 digits left. Keep one place to the right. "BKMGTPE". n==0 => 'B'; n==4 => 'T'. 8
by 8bitsrule 5y ago
Overkill. KISS. n counts moving the decimal left 3 places until there are <=3 digits left. Keep one place to the right.
"BKMGTPE". n==0 => 'B'; n==4 => 'T'.
810 has 3 digits. n==0, 810B.
999950 has 6 digits. n==1, you've got 999.9K
1100000 has 7 digits. n==2, 1.1M
1234567890 has 10 digits. n==3, 1.2G