Converting a number to next 0.5 in excel - excel-2007

Please help in to convert number to next 0.5 in excel.
example:
1.30 converts to 1.5,
1.499 converts to 1.5
1.510 converts to 2
4.012 converts to 4.5
4.5006 converts to 5
0.12 converts to 0.5
0.731 converts to 1
i.e converts to next 0.5.
I tried some functions but couldnt get a solution.

Nice Question!
The ROUNDUP Formula is
=IF(ROUNDUP(A1,0)-A1 >= .5 , ROUNDUP(A1,0)-.5, ROUNDUP(A1,0))
Explanation
If it takes 0.5 or more to round the number up to the nearest integer, then we can use the rounded integer - 0.5 to bring the number to the nearest .5
If it takes less than 0.5 to round it up, then the rounded up integer is the answer.

A much cleaner solution to use is
floor(A1 * 2 + 0.5) / 2

Use the CEILING function:
=CEILING(A1,0.5)

Related

Rounding the 3rd decimal down in teradata

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

Postgres eliminates decimal precision when casting a large float where first number in decimal portion <= 1 to real dtype

If you cast a large enough number with decimal precision to real where the first number in the decimal portion is less than or equal to 1 then the decimal portion is eliminated.
-- decimal precision is captured
-- 3 x 10^5 + 0.1
select 300000.1::real
OUTPUT:
300000.1
-- decimal precision is not captured
-- 3 x 10^6 + 0.1
select 3000000.1::real
OUTPUT:
3000000
-- decimal precision is captured
-- 3 x 10^6 + 0.2
select 3000000.2::real
OUTPUT:
3000000.2
I checked Postgres documentation and see that real dtype is "variable-precision, inexact" with a range of "6 decimal digits precision". I am not sure why decimal precision is captured in the third example but not the second since the size of the number is the same, just a larger decimal portion. Can someone explain this please?
That's just a coincidence.
real is stored in binary, so when you exceed the precision, it's the luck of the draw how far from the intended decimal number the value is.

Rounding of Decimal values

Is there any function in sql which rounds of the value to nearest whole number.
For example,
If value is 12.56 then it should be 13.
If value is 12.34 then it should be 12.
I tried with Ceiling and floor but it doesn't give me accurate result. Ceiling gives me both the value as 13 where as i need 13 and 12 depending on my value.
Is there any function that i can use to get the desired result I want?
Any help is appreciated!
I figured it out.
I just used ROUND(value,0) which gave me desired result.
If you don't care about your decimal values being saved, like the people said ROUND() will work, just pass the second parameter as 0 to say that you don't care about the decimal places, Precision = 0 = NO Decimal, so for example:
DECLARE #floater FLOAT = 2.50
SELECT ROUND(#floater, 0) --Returns 3
SET #floater = 2.10
SELECT ROUND(#floater, 0) --Returns 2

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.