如何将0.00001转换成1.00E-05 ?
之前写了一个,不过都是正数的,负数的话先把前面的负号去掉在用
function science($num){
if($num > 1){
$temp = $num;
$pow = strlen($temp)-1;
}else{
$temp = 1/$num;
$pow = -(strlen($temp)-1);
}
$base = $temp/pow(10, abs($pow));
return $base.'E'.$pow;
}
Fractal大佬的方法更好,我之前没发现,学习到了。
2 回答1.5k 阅读✓ 已解决
1 回答1.3k 阅读✓ 已解决
2 回答930 阅读✓ 已解决
1 回答1.1k 阅读✓ 已解决
2 回答993 阅读
1 回答963 阅读
1 回答885 阅读
php 自带函数
参考官方文档 sprintf
e
The argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).
E
Like the
e
specifier but uses uppercase letter (e.g. 1.2E+2).