How to format numbers similar to Stack Overflow reputation format

前端 未结 8 1028
我在风中等你
我在风中等你 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:13

    I created an npm (and bower) module to do this:

    npm install --save approximate-number
    

    Usage:

    var approx = require('approximate-number');
    approx(123456); // "123k" 
    

提交回复
热议问题