RE: Representing microtime() values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> >>Hi everyone
>> >>
>> >>Here's a small problem that I haven't been able to figure out and hence I
>> >>figured I'd post and see if anyone can explain this to me.
>> >>
>> >>-snip-
>> >>
>> >How exactly does PHP handle these values internally? Does anyone know?
>> >
>> >Tomi:
>> >
>> >Try this:
>> >
>> >http://www.webbytedd.com/b/timed/
>> >
>> >HTH's
>> >
>> >tedd
>> 
>> Thanks Tedd, but that's not really what I asked for. The difference in your
>> script is that it doesn't use the TRUE flag (unlike the script given on
>> PHP's manual). But not much of anything else. PHP still behaves the same way
>> with the float numbers when you try to look at them. And that is the part
>> that I wish to understand.
>> 
>> PHP clearly stores a number with more than two decimal points when you call
>> microtime(). But when you print it, it only shows two.

>that seems to me like a floating point precision issue. after all, the
>integer part of the microtime result is a quite big number...
>
>I even tried a workaround like
>
>$a = explode(' ', microtime());
>echo $a[0] + $a[1];
>
>but it resulted in the exact same result like microtime(true)
>
>anyone knows something for sure?
>
>greets
>Zoltán Németh 

Precision issue is what I also thought of. But it does seem quite strange to me that anything with more than two float points would loss precision so badly it isn't worth letting people to print out.

Here is one workaround:

$a = explode(' ', microtime());
echo bcadd($a[0], $a[1], 6);

But this way the output is a string. Casting it implicitly as integer will erase the floating points. As will passing it into the round() function.

Anyone know a workaround without using the bcmath library?


Tomi Kaistila
PHP Developer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux