JavaScript Number.toLocaleString() with 4 digits after separator

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

    You cannot do this with toLocaleString() alone. But you can round to 4 decimal places before displaying:

    var n = Math.round(number * 10000) / 10000;
    document.getElementById('id').innerText = n.toLocaleString();
    

提交回复
热议问题