Convert long number into abbreviated string in JavaScript, with a special shortness requirement

前端 未结 16 2526
名媛妹妹
名媛妹妹 2020-11-30 22:33

In JavaScript, how would one write a function that converts a given [edit: positive integer] number (below 100 billion) into a 3-letter abbreviation -- where 0-9 an

16条回答
  •  感动是毒
    2020-11-30 22:50

    I think you cant try this numeraljs/

    If you want convert 1000 to 1k

    console.log(numeral(1000).format('0a'));
    

    and if you want convert 123400 to 123.4k try this

    console.log(numeral(123400).format('0.0a'));
    

提交回复
热议问题