PHP how to convert number exponential number to string?

余生长醉 提交于 2019-12-23 17:18:35

问题


I have a number stored in scientific notation

2.01421700079E+14

I've tried using float, string, int and I can't get

0201421700079085 from 2.01421700079E+14

1. echo (float)$awb;
2. echo number_format($awb, 0, '', '');
3. echo (int)$awb;
4. echo (string)$awb;
  1. 2.01421700079E+14 = float
  2. 201421700079085 = number
  3. 201421700079085 = int
  4. 2.01421700079E+14 = string

回答1:


printf and friends will do this:

<?php
$awb = 2.01421700079E+14;
$str = sprintf("%d", $awb);
var_dump($str);

Output:

string(15) "201421700079000"

There obviously isn't enough information in your original number to get any more precision than that.




回答2:


Try this:

number_format(1.2378147769392E+14,0,'','')


来源:https://stackoverflow.com/questions/43510301/php-how-to-convert-number-exponential-number-to-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!