Using the math functions

List of PHP math functoins: http://www.php.net/manual/en/ref.math.php

Common math functions

abs($value)
ceil($value)
floor($value)
max($n1, $n2[, $n3] ...)
min($n1, $n2[, $n3] ...)
pi()
pow($base, $exp)
round($value[, $precision])
sqrt($value)

How to round a number

<?php
  $subtotal = 15.99;
  $tax_rate = 0.08;
  $tax = round($subtotal * $tax_rate, 2);  // 1.28
?>

How to get the square root of a number

<?php
  $num1 = 4;
  $root = sqrt($num1);          // 2
?>

How to work with exponents

<?php
  $num2 = 5; 
  $power = pow($num2, 2);       // 25
?>

Back