Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Rounding off decimal

Author  Topic 

Kotti
Posting Yak Master

129 Posts

Posted - 2008-11-07 : 08:09:23
Hi friends,

i am calculating average rating according to no of persons and the maximum rating will be 5.

what i need is ,if i my avg rating is from 0.01 to 0.49 it must take the value as 0.50 and if it from 0.51 to 0.99 it must take the value as 1.00

Like that for 1.01 to 1.49 as 1.50 and 1.51 to 1.99 as 2.00

This will be upto 5

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-07 : 08:24:15
[code]DECLARE @Sample TABLE
(
value SMALLMONEY
)

INSERT @Sample
SELECT 1.01 UNION ALL
SELECT 1.49 UNION ALL
SELECT 1.50 UNION ALL
SELECT 1.51 UNION ALL
SELECT 1.99 UNION ALL
SELECT 2.00

SELECT value,
(100 * value + 50 - 100 * value % 50) / 100 AS Peso
FROM @Sample[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -