11

What is the implementation of reputation points formatting used on Stack Overflow?

Like, 10000 reputation points is displayed as 10k.

And 1000 is displayed as 1,000.

And sometimes, it is rounded and then a k is added.

6

1 Answer 1

3

Finally, after no one came up on this, I've found a way which replicates what SO does, approximately.

Here is the C#-code which I used and will use in my website ;)

public static string ReadableReps(int reps)
{
   return reps < 10000
       ? reps.ToString("N0") // or just N for culture specific
       : Math.Round(reps / 1000.0, 1) + "k";
}
7
  • 3
    Pro Tip: the else is redundant.
    – user823738
    Commented May 4, 2014 at 11:13
  • @Zaffy, why? It isn't redundant.
    – Amit Joki
    Commented May 4, 2014 at 11:17
  • 1
    Well, the execution would be the same even without the else. Because return terminates the current function thats being executed.
    – user823738
    Commented May 4, 2014 at 11:21
  • Also see this stackoverflow.com/q/19990446/823738
    – user823738
    Commented May 4, 2014 at 11:23
  • Just empirically from looking at the numbers in a few posts, I believe there is no decimal for users with at least 100k. So it's the full number for rep < 10k, one decimal for 10k <= rep < 100k, no decimal for rep >= 100k. Commented Jul 4, 2014 at 0:27
  • @Zaffy updated...
    – Amit Joki
    Commented Jul 4, 2014 at 2:22
  • This changed (or broke) recently. My 16563 should round to 16.6k, but on posts it is currently just 16.5k. Seems like today or yesterday things changed. Commented May 27, 2015 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .