Reputation: 1070
I have an XML field that I try to print it with commas in the thousands (example : 1,234)
this is my code :
<span><%=String.Format("{0:n}", dc.GetXMLField(nl[i], "PRICE")) + " ₪"%></span>
When I run this, I get the number without any commas (for example : 200000) by the way, its a string..
thanks for the helpers.
Upvotes: 0
Views: 125
Reputation: 10105
int Number = 0;
if (int.TryParse("200000", out Number))
{
Response.Write(String.Format("{0:n}", Number, "PRICE"));
}
Result - 200,000.00
(200000).ToString("N", new System.Globalization.CultureInfo("en-US"));
Result - $200,000.00
String.Format("{0:C}", 200000);
Result - 200,000.00
Upvotes: 0
Reputation: 41308
dc.GetXMLField
is returning a string, not a formatable number (int, decimal, etc), but in order for string.Format("{0:n}", num)
to work, num has to be an actual
number, not a string representation of a number.
If you know this will always be a number you could parse it into a number first, before attempting to format it:
String.Format("{0:n}", int.Parse(dc.GetXMLField(nl[i], "PRICE")))
Upvotes: 2