请给我一个原生的JavaScript函数(请不要使用jQuery,Prototype等库)用于将数字转换为下列格式:
input: 0.39, 2.5, 4.25, 5.5, 6.75, 7.75, 8.5
output: 0.39, 2.50, 4.25, 5.50, 6.75, 7.75, 8.50
例如,在Ruby中,我会像这样做:
>> sprintf("%.2f", 2.5)
=> "2.50"
输出可能是数字或字符串。我并不关心,因为我只是用它来设置 innerHTML
。
谢谢。
5.52
,因为这似乎是Number.prototype.toFixed()
返回的结果,并且我接受它作为答案。 - ma11hew28