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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Rounding off issue

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2013-12-13 : 23:00:07


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)

17689 Posts

Posted - 2013-12-13 : 23:46:48
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
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-14 : 07:33:53
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

377 Posts

Posted - 2013-12-14 : 17:34:01
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)

17689 Posts

Posted - 2013-12-15 : 08:58:35
[code]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
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -