PHP-Mathematical Functions


ABS(expr)
  
This function returns the absolute (positive) value of expr.

SIGN(expr)
  
This function returns -1, 0, or 1 depending on whether expr is negative, zero, or positive, respectively.

MOD(expr1,expr2),expr1 % expr2
  
This function returns the remainder of dividing expr1 by expr2.

FLOOR(expr)
  
This function rounds down expr. returns the largest integer value that is less than or equal to expr.

CEILING(expr)
  
This function rounds up expr . returns the smallest integer value that is greater than or equal to expr.

ROUND(expr)
  
This function returns expr rounded to the nearest integer. Note that the behaviour when the value is exactly an integer plus 0.5 is system dependant. Thus, you should not rely on any particular outcome when migrating to a new system.

ROUND(expr,num)
  
This function rounds expr to a number with num decimal places, leaving trailing zeroes in place. Use num=2, for example, to format a number as dollars and cents. Note that the same uncertainty about the rounding of 0.5 applies as discussed for ROUND above.

EXP(expr)
  
This function returns eexpr, the base of natural logarithms raised to the power of expr.

LOG(expr)
  
This function returns ln expr, or logarithm of expr.

Remember, a logarithm with an arbitrary base B can be calculated as LOG(expr)/LOG(B).

LOG10(expr)
  
This function returns the base-10 logarithm of expr.

POW(expr1,expr2),POWER(expr1,expr2)
  
This function returns expr1 raised to the power of expr2.

SQRT(expr)
  
This function returns the square root of expr.

PI()
  
This function returns the value of πpi.

COS(expr)
  
This function returns the cosine of expr in radians
SIN(expr)
  
This function returns the sine of expr in radians (e.g. SIN(PI()) = 0).
TAN(expr)
  
This function returns the tangent of expr in radians (e.g. TAN(PI()) = 0).
ACOS(expr)
  
This function returns the arc cosine (cos-1 or inverse cosine) of expr (e.g. ACOS(-1) = 3.141593).
ASIN(expr)
  
This function returns the arc sine (sin-1 or inverse sine) of expr (e.g. ASIN(0) = 3.141593).
ATAN(expr)
  
This function returns the arc tangent (tan-1 or inverse tangent) of expr (e.g. ATAN(0) = 3.141593).
ATAN(y,x),ATAN2(y,x)
  
This function returns the angle (in radians) made at the origin between the positive x axis and the point (x,y) (e.g. ATAN(1,0) = 1.570796).
COT(expr)
  
This function returns the cotangent of expr (e.g. COT(PI()/2) = 0).
RAND(),RAND(expr)
  
This function returns a random, floating point number between 0.0 and 1.0. If expr is specified, a random number will be generated based on that value, which will always be the same.
LEAST(expr1,expr2,...)
  
This function returns the smallest of the values specified.

GREATEST(expr1,expr2,...)
  
This function returns the largest of the values specified.
DEGREES(expr)
  
This function returns the value of expr (in radians) in 
degrees.
RADIANS(expr)
  
This function returns the value of expr (in degrees) in radians.
TRUNCATE(expr,num)
  
This function returns the value of floating point number expr truncated to num decimal places