HAJJAJ
HAJJAJ

Reputation: 3787

number formatting in asp.net markup code?

I have used almost all ways to format numbers in asp.net markup code, I have used the below ways and none of them worked with me :

 <%# String.Format("{0:C}", Eval("Netprofit") ) %>
 <%# string.Format("{0:#,###}",  Eval("Netprofit").ToString()) %> ,
 <%# DataBinder.Eval(Container.DataItem, "Netprofit", "{0:#,###}") %> ,
 <%# string.Format((new System.Globalization.CultureInfo("en-US")).NumberFormat, "{0:#,###}", Eval("Assets","{0:#,###}").ToString()) %>
 <%# string.Format("{0:C2}",  Eval("Netprofit").ToString()) %> ,
 <%# DataBinder.Eval(Container.DataItem, "Netprofit", "{0:C2}") %> ,
 <%# string.Format((new System.Globalization.CultureInfo("en-US")).NumberFormat, "{0:C2}", Eval("Assets","{0:C2}").ToString()) %>

any other suggestions I need to make the number: (908934) looks like: (908,934)

Upvotes: 0

Views: 1308

Answers (3)

Access Denied
Access Denied

Reputation: 9501

"N0" in "en-US" culture is what you need.

<%#string.Format(new System.Globalization.CultureInfo("en-US"),"{0:N0}",Eval("Netprofit")) %>

Take a look at docs.

1234.567 ("N", en-US) -> 1,234.57

Upvotes: 1

HAJJAJ
HAJJAJ

Reputation: 3787

I figured it out, I had to convert the string to Decimal first then it works :

<%# string.Format(new System.Globalization.CultureInfo("en-US"), "{0:N0}",  Convert.ToDecimal(Eval("Assets"))) %>

Thanks, everyone, I really appreciate your help.

Upvotes: 0

Afz Al
Afz Al

Reputation: 11

Try something like this

asp:BoundField HeaderText="Your Header" DataField="Some Numbers" DataFormatString="{0:0,0.00}" //Edit the format according to your need

Upvotes: 0

Related Questions