March 7, 2006 at 5:16 am
Hello SQL Server Central folks,
I have a question relating to the formatting of output from a query. The output is 60.12456 how do I format my field so it is displayed as 60.12?
Simple it may be, but I can't fathom it out.
Thanks.
Nick
March 7, 2006 at 5:59 am
There are couple of ways of doing it...one is:
declare @table table
(col1 numeric(9,5))
insert into @table values (60.12456)
select col1, cast (col1 as numeric(6, 2)) changed_val from @table
--Output
col1 changed_val
----------- -----------
60.12456 60.12
March 7, 2006 at 6:41 am
Many thanks
Nick
March 7, 2006 at 7:05 am
Beware of rounding, ie
DECLARE @number numeric(9,5)
SET @number = 60.99999
SELECT @number,CAST(@number AS numeric(6, 2))
result
60.99999 61.00
SELECT @number,CAST(ROUND(@number,2,1) AS numeric(6, 2))
result
60.99999 60.99
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply