How to format numbers similar to Stack Overflow reputation format

前端 未结 8 1026
我在风中等你
我在风中等你 2020-11-27 06:41

I want to convert a number into a string representation with a format similar to Stack Overflow reputation display.

e.g.

  • 999 == \'999\'
  • 1000 =
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 07:12

    divide by 1000 then if result is greater than 1 round the number and concantenate a "k" on the end.

    If the result is less than 1 just output the actual result!

提交回复
热议问题