Rounding the 3rd decimal down in teradata - sql

I'm looking to round some decimals to a maximum of 2 decimals, but always rounded down.
example:
I have 1.999 and want it rounded down to 1.99
Likewise; 1.175 should be rounded down to 1.17
So basically I'm looking for a FLOOR function but not on integers but on decimals. Does anyone know if a similar function exists?
Thanks!

Found the solution,
Use the TRUNC function with 2 decimals, eg: TRUNC (1.999, 2) return 1.99

Related

How to round up to the 16th decimal place in sqlite

I would like to know how to extend to the 16th decimal place in SQLite e.g
SELECT 799.9/150.0 --Answer rounded up to the 16th decimal place.
SQLite has a function called round which can be used to round floating point numbers to a specified precision:
SQLite round() function rounds a floating-point value t up to a number of digits to the right of the decimal point. If the 2nd argument (rounded digits) is omitted, it is assumed to be 0.
To round a number up to the 16th decimal place, you'd have to modify your query to look like this:
SELECT round(799.9/150.0, 16)
This outputs the number 5.332666666666667.
If you want no decimals at all, you can omit the second parameter:
SELECT round(799.9/150.0)
This will return 5.0

SQL keep two decimal places for integers after converting cent into dollar

I am trying convert number values stored in the database as cents into dollar and keep 2 decimal places.
The following code will work only if v_cent/100.00 is NOT integer
SELECT CAST(ROUND(v_cent/100.00, 2) AS NUMERIC(8,2)) FROM DUAL;
If v_cent = 20000 then the result is 200.
How could I reserve 2 decimal places even if the result is integer?
Use to_char(), say to convert this to an output format with two decimal places:
select to_char(v_cent / 100.0, 'FM999999.99')
from dual;
As for your formulation it is doing the right thing. The only issue is that the decimal points are not printed out by default.

sql server round

select round((cast(56/3 AS DECIMAL (4,2))),1)
is showing 18 output instead of 19 , where as actual value is 18.66.
My Round function is not working
please help.
The problem is 56/3 is an integer calculation which means no floating point numbers.
You need to use floating point numbers in the initial calculation e.g. 56.0/3. Also, if you want to round to 19 then you need to round to the nearest whole number, ROUND(x, 1) will round to the first decimal place - you need to pass 0 to round up to 19.
SELECT ROUND((CAST(56.0/3 AS DECIMAL (4,2))),0)
Alternatively, you could switch ROUND for CEILING
select CEILING(CAST(56.0/3 AS DECIMAL(4,2)))
Your section of the code:
CAST( 56/3 AS DECIMAL )
First evaluates the 56/3 which returns 18. This is then cast to decimal, giving 18.0.
You need to cast either the numerator or denominator before the division occurs.
The round function is working fine -- it's just not using the input you think it is.
Convert one of your integer values before you divide the numbers:
select round(56/convert(DECIMAL (4,2),3),0);
If you do not so you divide integers which results in 18 not 18.66

sql server rounding depending on decimal value

I have a decimal (18,2) column and when I do my select would like for it to round up/down depending on the decimal value.
Example:
value
1.50 -> 2
1.25 -> 1
so the basic decimal rule: >= .5 rounds up and < .5 round down
I've seen "Ceiling" round ups and "Floor" rounds down but I need to do both depending on the value. Any ideas?
You can use the ROUND() Function something like this....
SELECT ROUND(Value,0)
SQL FIDDLE
You need to use round function to round the column value in select statement. Please try following
select ROUNDUP(COLUMN_NAME, 0) FROM TABLE_NAME

divide drops remainder in DB2 SQL

So I'm dividing an integer by a decimal, and storing the result in a decimal column. However, it always drops the fractional component(the part after the decimal point). If I multiply the result by 10 or 100 I get a more accurate result, but dividing again drops the fractional part again.
The two fields I've inserted into were a precision 5, scale 0 decimal and a precision 5, scale 3 decimal.
I've also tried casting the integer into a decimal and that doesn't make a difference, neither does multiplying by 1.0.
I'm out of ideas or tricks to try.
Thanks, Buzkie
Turns out I was casting incorrectly. After doing using the correct format
CAST(int AS DECIMAL(5,3))
it worked. I had left off the precision and scale before.