Ask a FLOAT question-php Tutorial

Source: Internet
Author: User
Ask a FLOAT question $ usec: number of current microseconds, $ sec: current number of seconds list ($ usec, $ sec) explode (, microtime (); $ time1 (float) $ usec + (float) $ sec; list ($ usec, $ sec) explode (, microtime (ask a FLOAT question)
// $ Usec: number of current microseconds, $ sec: current number of seconds
List ($ usec, $ sec) = explode ('', microtime ());
$ Time1 = (float) $ usec + (float) $ sec;

List ($ usec, $ sec) = explode ('', microtime ());
$ Time2 = (float) $ usec + (float) $ sec;

Echo $ time2-$ time1;

The result outputs a number similar to this: 3.40938568115E-5.

Problem:
Print $ usec and $ sec separately, and output the following number: 0.95312700 1326693637
$ Time output: 1326693637.95
Why does $ time1-$ time2 output "3.40938568115E-5 "???

Thank you.


------ Solution --------------------
Discussion

Reference:

You can customize the format.
PHP code

Echo sprintf ('%. 16f', $ time2-$ time1 );

I don't know why this happens by default...

------ Solution --------------------
Because the value is too small to be represented by decimal places, it can only be represented by scientific notation.
------ Solution --------------------
Because your $ time2-$ time1 value is too small, it is about 0.0000340938568115
In this way, the previous 0 values affect the accuracy display, so it is automatically changed to scientific notation.
3.40938568115E-5 is equivalent to 3.40938568115*10 ^-5
------ Solution --------------------
Discussion

In fact, I mean:
$ Time1 and $ time2 are similar to the following numbers: 1326693637.95
Then they subtract two decimal places. why are there so many decimal places ??

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.