Home  >  Article  >  Backend Development  >  PHP scientific notation conversion to normal numerical output solution

PHP scientific notation conversion to normal numerical output solution

WBOY
WBOYOriginal
2016-07-29 08:59:552217browse

Go directly to the code

/**
 * @param $num         科学计数法字符串  如 2.1E-5
 * @param int $double 小数点保留位数 默认5位
 * @return string
 */

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

echo sctonum(2.1E-5, 6); //输出0.000021

The above introduces the PHP scientific notation method to convert normal numerical output solution, including aspects of the content, I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn