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 2000 Forums
 Transact-SQL (2000)
 chaning the format of a number

Author  Topic 

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-07-10 : 10:52:58
I need change the format of an object float(8) named C2

In MsAccess I can simply do this...
Format([C2],"#.##")

Original Number
C2 = 0.154

Expected Results
C2 = 0.15

I am unsure how to do this in SQL

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-07-10 : 11:25:17
Don't format your data with T-SQL. It is not designed to do that. Just return the data back. Let your client format it.



- Jeff
Go to Top of Page

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-07-10 : 11:26:44
I need to do this before the client gets a hold of the data
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-07-10 : 11:27:56
Are you looking to round the output?


declare @C2 float(8)
set @C2 = '0.154'

select @C2, round(@C2, 2)


Nathan Skerl
Go to Top of Page

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-07-10 : 11:34:52
I tried that.

Original
C2 = 0.154

Round results
C2 = 0.150

I need the "0" to dissappear.


Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-07-10 : 12:41:50
?

declare @C2 float(8)
set @C2 = '0.154'

select @C2, cast(cast(@C2 as decimal(8, 2)) as varchar(10))

/*results
------------------------ ----------
0.154 0.15
*/


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-11 : 02:10:35
quote:
Originally posted by chippyles

I need to do this before the client gets a hold of the data



Do you use front end application? If so, use format function there. You can use Ryan's method but actually it is varchar and not Numeric so that you cant use it for calculations until you convert it back to numeric

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -