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.
Author |
Topic |
shemayb
Posting Yak Master
159 Posts |
Posted - 2008-02-25 : 14:31:20
|
My situation is this,I want to format my currency result to be rounded off by two decimal places.For example i have 45.683.I want my result to give me 45.68 but in the string.format that i used: string Dtotal = string.Format("{0:c}", str_total_charges);my result gives me $45.68. How can i remove the dollar sign?Funnyfrog |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-02-25 : 14:52:42
|
use: string.format("{0:00}")this is all explained in the MSDN documentation on format strings, with tons of examples and everything:http://msdn2.microsoft.com/en-us/library/0c899ak8(vs.71).aspx- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2008-02-25 : 15:16:32
|
string Dtotal = string.Format("{0.00}", str_total_charges);i tried to apply the one above but i have an error which says that input string was not in the correct format.Funnyfrog |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-02-25 : 16:28:29
|
What data type is str_total_charges? I assume a string? If so, why are you storing a decimal value in a string variable? Always use the proper data types for the data you are holding. You need to convert your str_total_charges to the correct data type before you can format it. this is why I say over and over do not convert data to VARCHAR in SQL Server, return native data types and then formatting in .NET is easy. If you convert everything to strings, you cannot format or sort or calculate things without first converting your data BACK to the proper type.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
shemayb
Posting Yak Master
159 Posts |
Posted - 2008-02-25 : 17:26:34
|
thank you so much for that.that helped a lot..I got it now..Funnyfrog |
|
|
|
|
|