码迷,mamicode.com
首页 > Web开发 > 详细

PHP的两个科学计数法转换为字符串的方法

时间:2017-03-04 19:05:35      阅读:407      评论:0      收藏:0      [点我收藏+]

标签:turn   pow   reg   常用   科学计数法   方法   pre   nbsp   rto   

不常用,所以整理在这里,分享给同行使用

 

方法一:取尾数法

public function NumToStr($num) {
        if (stripos($num, e) === false)
            return $num;
        $num = trim(preg_replace(/[=\‘"]/, ‘‘, $num, 1), "); //出现科学计数法,还原成字符串
        $result = "";
        while ($num > 0) {
            $v = $num - floor($num / 10) * 10;
            $num = floor($num / 10);
            $result = $v . $result;
        }
        return $result;
    }

方法二:数字规律法

function sctonum($num){
    if(false !== stripos($num, "e")){
        $a = explode("e",strtolower($num));
        return bcmul($a[0], bcpow(10, $a[1]));
    }
}

 

PHP的两个科学计数法转换为字符串的方法

标签:turn   pow   reg   常用   科学计数法   方法   pre   nbsp   rto   

原文地址:http://www.cnblogs.com/shangxia/p/6501948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!