Challenge
Take a number and output it with 4 digits or less using letters and numbers. For example; 270,030
would turn into 270K
.
Key
Billion -> B
Million -> M
Thousand -> K
Rules
- You may choose to accept input numbers that include commas delimiting every three decimal places (such as
123,456,789
). - Round to nearest, half-up.
- Numbers will only go up to
999,499,999,999
. - The mantissa part of the answer should be at least 1.
- All letters must be uppercase and as specified above.
- Outputs must be 4 or less digits. (including letters such as
B
,K
, andM
) - Outputs must be as mathematically precise as possible. Example:
15,480
->20K
NOT OK15,480
->15.5K
GOOD
- If there are multiple outputs with the same mathematical precision, return either one. Example:
1000
->1000
GOOD1000
->1K
GOOD
Examples:
1,234,567 -> 1.23M 999,500 -> 1M 999,499 -> 999K 102 -> 102 1000 -> 1K 1001 -> 1001 100,000 -> 100K 12,345,678,912 -> 12.3B 1,452,815,612 -> 1.45B
Submissions
- This is code-golf, so the shortest solution in each language wins
- Standard Loopholes Apply