JavaScript Number.toLocaleString() with 4 digits after separator

后端 未结 5 1031
长情又很酷
长情又很酷 2020-12-16 09:03

Is there a way to get number.toLocaleString() with 4 digits after the comma?

Example:

var number = 49.9712;
document.getElementById(\'id         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-16 09:25

    I found that

    var number = 49.9712;
    number.toLocaleString( { minimumFractionDigits: 4 })
    

    gave the result of "49.971"

    In order to actually get the 4 decimal place digits, I did this:

    number.toLocaleString(undefined, { minimumFractionDigits: 4 })
    

    Also filling in a country code worked:

    number.toLocaleString('en-US', { minimumFractionDigits: 4 })
    

    In both cases I got 49.9712 for the answer.

提交回复
热议问题