user3241285 user3241285 - 1 month ago 8
SQL Question

Why does round(143.23,-1) return 140?

For the query

SELECT round(143.23, -1)
FROM dual


I thought that the output will be 142 but the output i got is 140
can anyone help me by explaining this.

Answer

The second parameter indicates how many digits of precision after the decimal point you want to preserve. Thus, -1 means one digit before the decimal point. I.e., you're losing the "ones" digit and rounding to the nearest "tens", resulting in 140.

To get a whole number (143 in this case), you can pass 0 as the second parameter, or just omit it entirely, as that's the default.