Skip to main content

toFixed

toFixed() 方法使用定点表示法来格式化一个数值。

function financial(x) {
return Number.parseFloat(x).toFixed(2);
}

console.log(financial(123.456));
// expected output: "123.46"

console.log(financial(0.004));
// expected output: "0.00"

console.log(financial("1.23e+5"));
// expected output: "123000.00"