|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55537 microtime(true) reports milliseconds, not microseconds
Submitted: 2011-08-30 10:39 UTC Modified: 2011-09-01 08:07 UTC
Avg. Score:3.3 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jacco at ovitech dot nl Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jacco at ovitech dot nl
New email:
PHP Version: OS:


 [2011-08-30 10:39 UTC] jacco at ovitech dot nl
From manual page:

When using the argument $get_as_float with value TRUE, the returned result has a precision of milliseconds instead of microseconds 

Test script:

echo '         time(): '.time()."\n";
echo 'microtime(true): '.microtime(true)."\n";
echo '    microtime():          '.microtime()."\n";

Expected result:
         time(): 1314699839
microtime(true): 1314699839.77298801
    microtime():          0.77288801 1314699839

Actual result:
         time(): 1314699839
microtime(true): 1314699839.7729
    microtime():          0.77288801 1314699839


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-31 20:15 UTC]
-Status: Open +Status: Bogus
 [2011-08-31 20:15 UTC]
If you print floats in PHP you won't get all digits printed out (as floats are very imprecise there could be many digits, infinitely many). If you want to see more digits you can use number_format. For eight digits after the comma you can use number_format(microtime(true), 8, '.', '')) for example. (Please note though that printing more digits won't necessarily give you a more precise number, again because of floating point precision.)
 [2011-09-01 07:26 UTC] jacco at ovitech dot net
Well, that is still a documentation issue if you ask me.

Maybe a note about this could be added to the documentation?
 [2011-09-01 08:07 UTC]
See also, the "precision" php.ini setting [1], which will be currently set to 14. 
If you want more digits in the float value from microtime() (or any float!) then 
change that setting.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Apr 04 06:01:23 2020 UTC