Format numbers in JavaScript similar to C#

后端 未结 18 2386
傲寒
傲寒 2020-11-22 12:26

Is there a simple way to format numbers in JavaScript, similar to the formatting methods available in C# (or VB.NET) via ToString(\"format_provider\") or

18条回答
  •  误落风尘
    2020-11-22 13:13

    To get a decimal with 2 numbers after the comma, you could just use:

    function nformat(a) {
       var b = parseInt(parseFloat(a)*100)/100;
       return b.toFixed(2);
    }
    

提交回复
热议问题