php.net |  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
Votes:3
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jacco at ovitech dot nl
New email:
PHP Version: OS:

 

 [2011-08-30 10:39 UTC] jacco at ovitech dot nl
Description:
------------
---
From manual page: http://www.php.net/function.microtime%23Return%20Values
---

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



Test script:
---------------
<pre><?php

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-31 20:15 UTC] nikic@php.net
-Status: Open +Status: Bogus
 [2011-08-31 20:15 UTC] nikic@php.net
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] salathe@php.net
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.

[1] php.net/ini.core#ini.precision
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC