
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Effect of Negative Second Argument on MySQL ROUND Function
If we specify the negative value of the second argument then the digits before the decimal point would be deleted and rounded off. The number of digits to be deleted depends upon the value of the negative second argument. Following examples will demonstrate the change, depending upon the negative value of the second argument, in the output of ROUND() function.
mysql> Select ROUND(1789.456,-1); +--------------------+ | ROUND(1789.456,-1) | +--------------------+ | 1790 | +--------------------+ 1 row in set (0.00 sec)
The query above returns 1790 because the first digit (which is to be deleted because of value -1) before the decimal point is 9 (which is > 5) hence the digit before this i.e. 8 would be rounded off to 9.
mysql> Select ROUND(1789.456,-2); +--------------------+ | ROUND(1789.456,-2) | +--------------------+ | 1800 | +--------------------+ 1 row in set (0.00 sec)
The query above returns 1800 because the second digit (which is to be deleted because of value -2) before the decimal point is 8 (which is > 5) hence the digit before this i.e. 7 would be rounded off to 8.
mysql> Select ROUND(1789.456,-3); +--------------------+ | ROUND(1789.456,-3) | +--------------------+ | 2000 | +--------------------+ 1 row in set (0.00 sec)
The query above returns 2000 because the third digit (which is to be deleted because of value -3) before the decimal point is 7 (which is > 5) hence the digit before this i.e. 1 would be rounded off to 2.
mysql> Select ROUND(1789.456,-4); +--------------------+ | ROUND(1789.456,-4) | +--------------------+ | 0 | +--------------------+ 1 row in set (0.00 sec)
The query above returns 0 because a total number of digits before the decimal point is 4 and the value of the second argument is -4.