javascript toFixed不用0填充

时间:2017-05-17 08:10:48

标签: javascript numbers

我有一个来自PouchDB / CouchDB的timepamp,以毫秒为单位,并且具有更精细的小数,如1494832547145.4412,想要使用它与进程pid一起创建带有模式TPID的db的id,以便更容易解析并使用它与新的日期(时间戳)我想有一个固定长度的timpestamp我做了一些像这样的测试

> a = 1494832547145.4412
1494832547145.4412
> a.toFixed()
'1494832547145'
> a.toFixed(4)
'1494832547145.4412'
> b = 1494832547145.441
1494832547145.441
> b.toFixed(4)
'1494832547145.4409'
> c = 1494832547145.44
> c.toFixed(3)
'1494832547145.440'
> c.toFixed(4)
'1494832547145.4399'
> c.toFixed(5)
'1494832547145.43994'
> c.toFixed(6)
'1494832547145.439941'
> c.toFixed(7)
'1494832547145.4399414'

这里发生了什么?为什么不用0填充?

0 个答案:

没有答案