August 20, 2009 at 1:31 pm
Hi Everyone,
What is there difference between the two
select ROUND(8493.65,0)
8494.00
declare @val float
set @val = 8493.65
select round(@val,0)
8494
Why is it showing decimal(s) even afer rounding in the first case.
Also, sometimes in the below stmt, it is getting rounded as expected.
But if iMart_Graduation take the same code and excute in another management studio,
it is showing decimal places even though am round to 0 decimal places.
Is there any settings in the management studio or what is wrong?
create table emp
(id int,
sal float
)
insert emp
select 1,8329.948
union all
select 2,4885.34
declare @sql varchar(100)
set @sql = 'select sal,round(sal*12,0) from emp'
exec (@sql)
August 20, 2009 at 2:58 pm
In the first instance, it is probably interpreting your constant as a decimal or numeric type.
declare @val decimal (6,2)
set @val = 8493.65
select round(@val,0)
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
August 20, 2009 at 7:27 pm
Thanks
August 20, 2009 at 7:58 pm
"Rounding" doesn't mean the same thing as "Formatting" and how ROUND displays a result really shouldn't matter... formatting should be done in the GUI especially on date, time, and currency types so that it can use local regional setting to determine how such things should be formatted in different areas of the world. Now, if you're outputing to a file, that's a different story. Then you can use different datatypes or even a function like STR here and there to brute force formatting. But, like I said, let the GUI do the formatting.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply