Showing posts with label 94where. Show all posts
Showing posts with label 94where. Show all posts

Wednesday, March 7, 2012

Rounding Issue

How can rounding function be used so that following result is
accomplished:
rounding of 112.945 should yield 112.94
where as
rounding of 112.946 should yield 112.95
*** Sent via Developersdex http://www.examnotes.net ***>> How can rounding function be used so that following result is
Use ROUND( @.v, 2, CASE WHEN RIGHT( @.v, 1) <= 5 THEN 1 ELSE 0 END )
Anith|||Well to me in your senerio > .004 rounds up, if you want to change that
behavior, subtract .005 prior to rounding... (ick)
"Vik Mohindra" <vikmohindra@.hotmail.com> wrote in message
news:ely3YxGmFHA.708@.TK2MSFTNGP09.phx.gbl...
> How can rounding function be used so that following result is
> accomplished:
> rounding of 112.945 should yield 112.94
> where as
> rounding of 112.946 should yield 112.95
>
> *** Sent via Developersdex http://www.examnotes.net ***
>|||This should do the trick, but please do some testing :)
declare @.value numeric(10,3)
set @.value = 112.995
select cast(round(@.value - 0.0001, 2) as numeric(10,2))
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Vik Mohindra" <vikmohindra@.hotmail.com> wrote in message
news:ely3YxGmFHA.708@.TK2MSFTNGP09.phx.gbl...
> How can rounding function be used so that following result is
> accomplished:
> rounding of 112.945 should yield 112.94
> where as
> rounding of 112.946 should yield 112.95
>
> *** Sent via Developersdex http://www.examnotes.net ***
>|||Thanks, but this does not seem to work.
*** Sent via Developersdex http://www.examnotes.net ***|||Right, right, you want the 6 to round up. Well, suptracting .001 should do
it then...
"Vik Mohindra" <vikmohindra@.hotmail.com> wrote in message
news:OYAO8JHmFHA.3960@.TK2MSFTNGP12.phx.gbl...
> Thanks, but this does not seem to work.
> *** Sent via Developersdex http://www.examnotes.net ***|||Thanks Louis..nice solution, it seems to work.
*** Sent via Developersdex http://www.examnotes.net ***