JavaScript Number.toLocaleString() with 4 digits after separator

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

    Quick solution:

    call it like this:

    console.log(localeN(value, 4));
    
    function localeN(v, n) {
        var i, f;
      
        i = Math.floor(v);
        f = v - i;
        return i.toLocaleString() + f.toFixed(n).substr(1);
    }
    

提交回复
热议问题