user3241285 - 11 months ago 53

SQL Question

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 Source

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.