Skip to main content
edited body; edited title
Source Link
RegDwight
  • 101
  • 1
  • 1
  • 5

How to format reputation numbers similar to Stack Exchange sites.

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.

How to format reputation numbers similar to Stack Exchange sites.

UPDATE

For JavaScript, see CMS's implementation below. It is much more elegant than the one i 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.

How to format reputation numbers similar to Stack Exchange sites

UPDATE

For JavaScript, see CMS's implementation below. It is much more elegant than the one I 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.

edited title
Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

Dev-Tip: How to format reputation numbers similar to Stack Exchange sites.

edited body
Source Link

UPDATE

For JavaScript, see CMS's implementation below. It is much more elegant than the one i 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(1100010100) == '10.1k'

Post an implementation in the language of your choice.

UPDATE

For JavaScript, see CMS's implementation below. It is much more elegant than the one i 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(11000) == '10.1k'

Post an implementation in the language of your choice.

UPDATE

For JavaScript, see CMS's implementation below. It is much more elegant than the one i 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.

added 165 characters in body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
added 58 characters in body; edited tags
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
Rollback to Revision 1
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
Rollback to Revision 2
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
spliced in a better implementation that i got offa the intertubes
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
deleted 6 characters in body; edited body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
Post Made Community Wiki by CommunityBot