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.
| Author |
Topic |
|
afroz
Starting Member
6 Posts |
Posted - 2011-05-24 : 01:36:19
|
| I'm Trying to round up decimal values by 0.25 Can any body Help me on this..please i'm badly stuck..For example,For 2.40 It shold show 2.502.35 to 2.502.15 To 2.252.60 To 2.75afrozz.. |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-05-24 : 02:54:42
|
| MAY BE THIS WILL HELP YOU TRY Declare @a numeric(10,2)Set @a=2.76--change this values and checkSELECT CASE WHEN @a<CEILING(@a) THEN CASE WHEN 1-(CEILING(@a)-@a)<.25 THEN @a-(1-(CEILING(@a)-@a))+.25 ELSE CASE WHEN 1-(CEILING(@a)-@a)<.50 THEN @a-(1-(CEILING(@a)-@a))+.50ELSE CASE WHEN 1-(CEILING(@a)-@a)<.75 THEN @a-(1-(CEILING(@a)-@a))+.75ELSE CEILING(@a)ENDENDENDENDIn Love... With Me! |
 |
|
|
mhorseman
Starting Member
44 Posts |
Posted - 2011-05-24 : 04:24:11
|
| A bit less typing ...declare @amt numeric(10,2)set @amt = 2.76select floor(@amt) + ceiling(@amt % 1 * 4) / 4Mark |
 |
|
|
afroz
Starting Member
6 Posts |
Posted - 2011-05-24 : 07:54:43
|
| Thanks mhorseman,you really saved my ****,i was looking for this .Also thanks to raghuveer125 for replying..Once again thanks guys..afrozz.. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-05-24 : 13:47:30
|
Here is one more for fun:DECLARE @Foo TABLE (Val DECIMAL(18,2))INSERT @Foo (Val)VALUES (2.35),(2.15),(2.60)SELECT CEILING(Val / 0.25) * 0.25FROM @Foo |
 |
|
|
|
|
|