To print a number in currency (dollar - $) format, use the following code
Create an object for NumberFormatInfo Class in the class level
protected System.Globalization.NumberFormatInfo nfi = null;
Then create an instance for the object and assign the CurrencySymbol and CurrencyDecimalDigits as below in the Page_Load Event
nfi = new System.Globalization.NumberFormatInfo();
nfi.CurrencyDecimalDigits = 0;
nfi.CurrencySymbol = "$";
In the ASPX page to print the number in currency format use the following code
<%#String.Format(nfi,"{0:C}", Convert.ToDecimal (DataBinder.Eval(Container.DataItem,"Price"))) %>
No comments:
Post a Comment