I have a Price column which has 'money' as the data type.
Then I populated some data into the table. I enter '1.00' in the Price column, then I used the following code to get the data:
Label2.Text = "$" + dataSet1.Tables["products"].Rows[0]["price"].toString();
However, the price is displayed as "$1.0000". But I believe it should display "$1.00". So how can I get rid off the two zeros at the end.
regardsUse string.format("{0:c}", yourvalue)
This will format it in the currency used by your web server.
If you want more control, use "$" & string.format("{0:#,##0.00}", yourvalue)|||Hi PDraigh
I think u may have goven me VB code, actually I was using C#..
string.format("{0:#,##0.00}", yourvalue)
In the above code, what does 'string' represent|||I assume it would still work. 'string' is just the System.String. It's not a variable or object I declared. "{0:#,##0.00}" is the string formatting instruction and 'yourvalue' is just whatever value you want to format using the instruction. Try it, I think it would work in C#, but I don't use C#, so not sure|||yep
String and Format should be capital, such as String.Format("{0:#,##0.00}", price);
However, I still get 2.0000 istead of 2.00|||try,
Label2.Text = String.Format("{0:$##,##0.00}",dataSet1.Tables["products"].Rows[0]["price"]);
or
Label2.Text = String.Format("{0:c}",dataSet1.Tables["products"].Rows[0]["price"]);
No comments:
Post a Comment