- Related Questions & Answers
- What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL TRUNCATE() function?
- What would be the effect on the output of MySQL LAST_INSERT_ID() function in the case on multiple-row insert?
- What is MySQL STRCMP() function and what would be the output of this function?
- What would be the output of MySQL ELT() function if the index number, provided as an argument, is not an integer?
- What happens with the output of MySQL EXPORT_SET() function if I will skip the value of the fifth argument i.e. a number of bits?
- What would be the effect on MySQL output if we have the combination of NULL and other values in the list of strings, provided as arguments in FIELD() function?
- What would be the output of MySQL SUM() function if a column having no values has been passed as its argument?
- Floor the decimal values in MySQL instead of round?
- What happens if the output of MySQL TIMEDIFF() function surpass the range value of TIME field?
- While linking the strings, if I will add a NULL value then what would be the output of a CONCAT_WS() function?
- How MySQL SUBSTRING_INDEX() function returns the substring if we provide the negative value of the argument ‘count’?
- Which MySQL function returns a specified number of characters of a string as output?
- While linking two strings, if I will add a NULL value then what would be the output of a CONCAT() function?
- What happens if the argument ‘count’ in MySQL SUBSTRING_INDEX() function has the value greater than the total number of occurrences of delimiter?
- What MySQL returns if the argument of QUOTE() function is NULL?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

Advertisements