简体   繁体   中英

php microtime() behaving differently

I'm working with an API which calculates a timestamp using the following function:

public function timestamp() {
  return round(microtime(TRUE) * 1000);
}

But when i call the function on my localhost and on my webhost, i get the following in return:

1.37872612307E+12

But if i get other people to run the same code on their server(and using http://writecodeonline.com/php/ ), i get the following, and correct timestamp back:

1378726142452

But why?

Running XAMPP on OSX, and on unoeuro.com webhost.

Based on @FrederikSpang comment

You can set precision setting in php.ini file. It should be greater than yours(14)

For ex my ini setting is 16 :

precision = 16

Check precision setting in your php.ini .

See how different values influence on output of your function: http://ideone.com/9MMLvD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM