JavaScript Number.toLocaleString() with 4 digits after separator

后端 未结 5 1028
长情又很酷
长情又很酷 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:44

    If you need to use Locale settings than I don't think you'll be able to specify that you need 4 decimal places, but you can obviously do this using other prototype methods, such as toFixed().

    Here's an example:

    var number = 12.3456
    number.toFixed(4)
    

提交回复
热议问题