English

# Mysql Math functions

How to use Math Functions In Mysql?

## Explanation

### MySQL Math Functions :

ROUND(X), ROUND(X,D) :
Returns the argument X, rounded to the nearest integer. If it contains two arguments, then returns X rounded to D decimal places.
mysql> select round(12.589);
--> 13
mysql> select round(-12.23);
--> -12
mysql> select round(5.258, 1);
--> 5.3
mysql> select round(5.258, -1);
--> 10
SIGN(X) :
Returns the sign of the given number as -1 if negative,0 if zero, or 1 if positive.
mysql> select sign(-89);
--> -1
mysql> select sign(0);
--> 0
mysql> select sign(123);
--> 1
SIN(X) :
Returns the sine value of X,X given in radians.
mysql> select sin(45);
--> 0.85090352453412
mysql> select sin(pi());
--> 1.2246063538224e-016
SQRT(X) :
Returns the square root of the number,the number should be a positive number.
mysql> select sqrt(144);
-->12
mysql> select sqrt(741);
--> 27.221315177632
TAN(X) :
Returns the tangent of X, where X is given in radians.
mysql> select tan(45);
-->1.6197751905439
mysql> select sqrt(90);
--> -1.9952004122082
TRUNCATE(X,D) :
The number is truncated to D digits after decimal point. If D is negative, the D digits before the decimal point are converted to 0.
mysql> select truncate(4.556,1);
--> 4.5
mysql> select truncate(444.556,-1);
--> 440

Ask Question