php-浮点数以指数形式显示 [英] php- floating point number shown in exponential form

查看:152
本文介绍了php-浮点数以指数形式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我为什么会发生这种情况,

Could anyone please tell me why this happens,

$a  = 0.000022

echo $a // 2.2E-5

我想看的是0.000022而不是2.2E-5

推荐答案

指数形式是每种(?)编程语言的内部用法(至少CPU看到"以这种方式浮动).使用 sprintf() 格式化输出

The exponential form is the internal one use by every (?) programming language (at least CPUs "sees" floats this way). Use sprintf() to format the output

echo sprintf('%f', $a);
// or (if you want to limit the number of fractional digits to lets say 6
echo sprintf('%.6f', $a);

有关格式参数的更多信息,请参见手册:sprintf() .

See Manual: sprintf() about more information about the format parameter.

这篇关于php-浮点数以指数形式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆