Rounding in SQL

I need to perform a rounding of a result. In Oracle it looks like this:

SALDO_TONELADA = (A.PESO * 20,0);

The value of column A.PESO is 24.432 and multiplied by 20 gives 488.640.

My goal was to receive a value of only 488, without the point and without values after the point.

I've tried using ROUND but it didn't solve my problem.

I know that in Excel there is a formula that formats a certain field like this:

=esquerda(488.640; 3)

And as an answer would have 488.

Can you tell me if in Oracle there is something to format the field to bring only X characters?

I don't know if it was clear, but I need the result to be with 2 or 3 characters to correct the calculation of other columns that depend on this result.

Author: Sorack, 2019-03-08

1 answers

It is possible to truncate the numbers after the decimal point with the function TRUNC but if the value is up to 488,999 the result will be 488.

The query would be:

TRUNC((A.PESO * 20),0)

See example: http://sqlfiddle.com/#! 4 / 2b76e4/9

If you want to round even the correct value would be 489 according to mathematical rule, in this case it would be the function round :

ROUND(A.PESO * 20)

Example: http://sqlfiddle.com/#! 4 / 2b76e4/4

 2
Author: LaƩrcio Lopes, 2019-03-08 16:55:02