phptimemicrotime

PHP microtime missing digits


In PHP, when using microtime(true), I am expecting to get in most cases 6 digits to the right of the decimal.

<?php
//version 5.5.31

$time = microtime();
$timeTrue = microtime(true);

var_dump($time, $timeTrue);

// string(21) "0.64728900 1462577720"
// float(1462577720.6473)
?>

Why is the float only showing the first four digits? Sometimes I only get three digits, which makes sense. Should it not be returning float(1462577720.647289). ie 6 digits in most cases, occasionally 5 digits?


Solution

  • You seem to be confusing precision with digits after the decimals point.

    Double precision floating points usually have a maximum precision of 14 to 16 digits and your example shows 14. Yes, all digits count. The decimal point is handled by another variable (at the floating point definition level).

    The same principle would apply to very large numbers which would also lose precision after 14-15 digits long.