dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Knowing the Sign of a Given Number in MySQL

See how to learn the sign of the number for computation purposes.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


For a given number, it may be necessary to know the sign of the number for computation purposes.

If it is positive, zero or negative, you may have respective case to work on. The signs are returned as 1, 0, -1 for positive number, zero and negative number respectively.

Case 1: Positive number

SELECT SIGN(234) AS SIGN;
where 234 is the value. 

+-------+
| SIGN  |
+-------+
|    1  |
+-------+

Case 2: Number is zero

SELECT SIGN(0) AS SIGN;
where 0 is the value. 

+-------+
| SIGN  |
+-------+
|    0  |
+-------+

Case 3: Negative number

SELECT SIGN(-64500) AS SIGN;
where -64500 is the value. 

+-------+
| SIGN  |
+-------+
|   -1  |
+-------+ 

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date