You probably do know that the different reputation levels on Stack Exchange are formatted differently when seen from the questions page / a post. There're all the rep-formatting rules:
- if a user has 1 to 999 (one to three digits) rep, it's left as-is.
- if a user has 1000 to 9999 rep (four digits), it receives the comma as a separator:
9,999
if a user has 10000 to 99999 rep (five digits), it's shortened and rounded. I.e., 16741 rep is formatted as
16.7k
, notice the dot separator unlike the comma for the lower rep (previous point).16750 will already result
16.8k
(since this seems to be fixed)16941 results in
16.9k
, 16950 rounds up to17k
, as well as does 17014, for example.99941 rounds to
99.9k
, 99950 rounds to100k
(this is something I actually hate with the rep-rounding on SE, because 100,000 is such a milestone, and 99950 is nowhere near).
If a user has 100000 to 999999 rep, it's rounded this way:
100100 rounds down to
100k
, 100500 rounds up to101k
. The thing is, the rounding is done, but the decimal part is stripped (unlike the four-digits rep).100450 rounds down to
100k
, no step to round 450 to 500. Nor does 100499 - it's still100k
.279843 rounds up to
280k
, and 399999 rounds to400k
.
As input, you're given the raw reputation, and output it as formatted.
You can consider that input won't receive any invalid numbers / non-numbers, or numbers with leading zeros, i.e. 0001234
.
Because Jon Skeet doesn't seem to be reaching 1,000,000 soon, your code must be as short as possible you don't need to handle the rep greater than one million (i.e. no special cases for 999500 and above).
.
for a decimal point and with a suffixedk
; subject to the caveat that if the third significant figure is0
and is to the right of the decimal point then the value is displayed only to 2 significant figures." The specific cutoffs could then be moved to a single list of test cases at the end of the post, which is more convenient for copy-pasting into a test framework. \$\endgroup\$