php常用数学计算

  1. 加减乘除余

     $a = 9;
     $b = 3;
     $c = $a + $b;
     $d = $a - $b;
     $e = $a * $b;
     $f = $a / $b;
     $g = $a % $b;
    
  2. 指数(幂)运算

     # 求a的b次方
     $a = 9;
     $b = 3;
     $c = pow($a, $b);
    
     # 求a的b次方根(注意当b为偶数时,结果只会返回正,而不是±)
     $a = 9;
     $b = 2;
     $c = pow($a, 1/$b);
     # 当$b = 2时
     $c = pow($a, 1/$b); 等价于 $c = sqrt($a);
    
  3. 对数运算

     # 求log以a为底b的对数(a的多少次幂等于b)
     $a = 9;
     $b = 3;
     $c = log($b,$a);
    
  4. php打印π前53位小数

     # %.53f 打印总位数不限、小数部分53位的小数
     echo sprintf('%.53f', pi());
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-07-08 16:49:59

results matching ""

    No results matching ""