UPDATE
For JavaScript, see CMS's implementation below. It is much more elegant than the one iI provide in the body of this Q.
// formats a number similar to the way stack exchange sites // format reputation. e.g. // for numbers 10000 the output is '10k' with one decimal place when needed function getRepString(rep) { var repString; if (rep
Output:
getRepString(999)
== '999'getRepString(1000)
== '1,000'getRepString(9999)
== '9,999'getRepString(10000)
== '10k'getRepString(10100)
== '10.1k'
Post an implementation in the language of your choice.