SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Rounding off issue
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sent_sara
Constraint Violating Yak Guru

India
366 Posts

Posted - 12/13/2013 :  23:00:07  Show Profile  Reply with Quote


Declare @hardcurrency Table(Rate numeric(28,4))
insert @hardcurrency
select 25000.0000
union all
select 3.0825
union all
select 950000.0000

select rate,round(1/rate,4) as ExRate
from @hardcurrency


whenever im rounding to 4 its coming as:
0.00000000000000000000000000000
0.32440000000000000000000000000
0.00000000000000000000000000000

Expected output should be :
ExRate
0.00004
0.3244
0.000001

if i got the scale value which is > 0 from the beginning itself mean then round off to 4 else until i get the number(>0) i need to round off there.


khtan
In (Som, Ni, Yak)

Singapore
17645 Posts

Posted - 12/13/2013 :  23:46:48  Show Profile  Reply with Quote
quote:
if i got the scale value which is > 0 from the beginning itself mean then round off to 4 else until i get the number(>0) i need to round off there.


what do you mean by that ?


KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/14/2013 :  07:33:53  Show Profile  Reply with Quote
you cant have variable scale value. You need to set based on available values the scale value you want and all values will be shown rounded based on it

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

India
366 Posts

Posted - 12/14/2013 :  17:34:01  Show Profile  Reply with Quote
can u please give some example for this?
quote:
Originally posted by visakh16

you cant have variable scale value. You need to set based on available values the scale value you want and all values will be shown rounded based on it

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17645 Posts

Posted - 12/15/2013 :  08:58:35  Show Profile  Reply with Quote
case 	when round(1/rate,4) <> 0
		then convert(numeric(28,10), round(1/rate,4))
		else convert(numeric(28,10), left(convert(varchar(max), 1/rate), patindex('%[1-9]%', convert(varchar(max), 1/rate))))
		end



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000