如何在php中打印一个非常小的浮点值?
我有一个打印计算每个页面的加载时间的函数:
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
$time_end = microtime_float();
$time = $time_end - $time_start;
但是当我回显 $time 时,我得到这样的结果:
5.60283660889E-5
但是我想要一个像 0.000000000000xxxx 这样的值,我该如何转换它?谢谢。
I have a function that print calculate the loading time of each page:
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
$time_end = microtime_float();
$time = $time_end - $time_start;
but when I echo the $time, I get something like this:
5.60283660889E-5
But I would like to have a value like 0.000000000000xxxx, how can I convert this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下
printf
函数Take a look at
printf
function不需要“float”函数,只需
将值返回为 float 即可。
要显示小数,请尝试
告诉 PHP 将输出格式化为具有 16 位小数的浮点数。
There's no need for your "float" function, just do
which returns the value as float.
To display the decimals, try
which tells PHP to format a float with 16 decimal places of output.