PHP如何将数字指数数字转换为字符串? [英] PHP how to convert number exponential number to string?
本文介绍了PHP如何将数字指数数字转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用科学计数法存储了一个数字
I have a number stored in scientific notation
2.01421700079E + 14
2.01421700079E+14
我尝试使用float,string,int却无法获取
I've tried using float, string, int and I can't get
0201421700079085 来自 2.01421700079E + 14
0201421700079085 from 2.01421700079E+14
1. echo (float)$awb;
2. echo number_format($awb, 0, '', '');
3. echo (int)$awb;
4. echo (string)$awb;
- 2.01421700079E + 14 =浮动
- 201421700079085 =数字
- 201421700079085 =整数
- 2.01421700079E + 14 =字符串
推荐答案
printf
和朋友会做这个:
printf
and friends will do this:
<?php
$awb = 2.01421700079E+14;
$str = sprintf("%d", $awb);
var_dump($str);
输出:
string(15) "201421700079000"
您的原始号码中显然没有足够的信息来获得比此更高的精度.
There obviously isn't enough information in your original number to get any more precision than that.
这篇关于PHP如何将数字指数数字转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文