0

I have a timespamp from PouchDB/CouchDB with in millis and has decimals for more fine precision like this 1494832547145.4412, a want to use it with the process pid to create the id for the db with pattern TPID to make it easier to parse and use it with new Date(timestamp) I'd like to have timpestamp with a fixed length and I made some test like this

> 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'

what's going on here? Why it's not padding with 0s?

  • Read this: http://stackoverflow.com/questions/588004/is-floating-point-math-broken – robertklep May 17 '17 at 08:16
  • > c.toFixed(3) '1494832547145.440' > c.toFixed(4) '1494832547145.4399' this is what I don't understand and like, if toFixed(3) give ...440 toFixed(4) have to five ...4400. I know about precition problem but this looks very odd to me. – Fabio Sun May 25 '17 at 06:56

0 Answers0