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 2005 Forums
 Transact-SQL (2005)
 format a string as currency ?

Author  Topic 

BitShift
Yak Posting Veteran

98 Posts

Posted - 2007-01-22 : 11:46:31
Ive got a char(10) field that holds currency values. How can format these to allways have 2 decimal places using either a cast or convert ?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-22 : 11:49:19
select cast(yourcolumnnamehere as numeric(12, 2))


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2007-02-22 : 06:53:38
how about if you have a variable amount i.e. it could be 12,14 digits in length, and you only want 2 decimal places?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-22 : 08:04:57
#1 -- always, always, always use correct datatypes to store your data. NEVER store currency values as a char(10).

#2 -- do not format data in sql server, format your data at the presentation layer -- webpage, report, client application, etc. Return Money and DateTime and Decimal and Int datatypes from your database, and use the formatting features of your front end to format the data. That is -- retrieve DATA from the database, and PRESENT the data at the PRESENTATION layer. It almost even makes sense if you think about it !

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -