Rounding in SQL

Asked

Viewed 746 times

2

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

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

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

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

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

I know that in Excel has 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 do not know if it was clear, but I need the result to be 2 or 3 characters to correct the calculation of other columns that depend on this result.

  • Related or duplicate: https://answall.com/q/5746/101 and https://answall.com/q/219211/101

  • There is no example to test and it does not say what would be "not enough". It is difficult to help you

  • This example I don’t have, I’m still developing within the application. Basically, I need to multiply a result from weight to value. and as a precise answer this value has only 3 characters

1 answer

2


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 as a mathematical rule, in this case it would be the function ROUND:

ROUND(A.PESO * 20)

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

  • Thanks @Laércio Lopes, I’ll try it here ...

  • If you solve your problem accept the answer as image: https://i.stack.Imgur.com/eyLkG.jpg

  • to use TRUNC no funf in Mysql, you know which one I can replace ?

  • In Mysql should be TRUNCATE, I corrected the argument of the function that should be 0.

  • Good, thank you !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.