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 |
reflex2dotnet
Yak Posting Veteran
99 Posts |
Posted - 2007-03-08 : 11:53:59
|
Hi all, How can i get $ 12.00 in a labels text? label1.text = dt.Rows(0)("price").ToString---> returns 12.00000 i want to correct it to 2 deciamls and also add a dollar sign. Can anyone help me in this? Thanks |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2007-03-08 : 12:06:25
|
Label1.text = dt.Rows(0)("price").ToString("c")Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-03-08 : 12:32:47
|
If dt is a datatable, then rows(0) will return an object. So, that ToString() method overload will not work since Object doesn't have that overload. You'd need to cast it to the proper datatype first (i.e., decimal), and then use ToString() in that manner. I find that it is easiest to simply use the static String.Format() method:label1.text = String.Format("{0:c}", dt.Rows(0))- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2007-03-08 : 12:37:37
|
label1.text = String.Format("{0:c}", dt.Rows(0)("price"))Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
reflex2dotnet
Yak Posting Veteran
99 Posts |
Posted - 2007-03-08 : 16:00:07
|
Thanks to all We can also get it asFormatCurrency(dt.rows(0)("price"))Thanks |
|
|
|
|
|