How to show prices in the format 0,00(ie for hundred 100,00)

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 11:28:30

问题


hii,

I am using devexpress grid control.In my grid there are price tabs,in that i want the prices column to show in the format 0,00....ie if my price is 3000 then it should show 3.000,00...help me please...It is for winforms and the frontend is c#.


回答1:


The DevExpress controls are rich and complex and there are a number of ways to do this.

The simplest is probably to set a column's display format as follows:

gridColumn.DisplayFormat.FormatString = "N2";
gridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;

FormatString can be any of the .NET standard or custom format strings (look in MSDN or google for "Standard numeric format strings", "Custom numeric format strings").




回答2:


For a devexpress XtraGrid you can use DevExpress.Utils.FormatInfo:

DevExpress.Utils.FormatInfo fi = new DevExpress.Utils.FormatInfo();
fi.FormatType = DevExpress.Utils.FormatType.Numeric;
fi.FormatString = "n2";
myColumn.DisplayFormat.Assign(fi);



回答3:


If you also want to include the currency sign:

decimal price = 49.99M;
string data = price.ToString("c");



回答4:


Currency formatting depends on system settings, and sometimes it is better to specify precision explicitly:

double price;
string text=price.ToString("N2"); // N3 for 3 digits , etc


来源:https://stackoverflow.com/questions/4895790/how-to-show-prices-in-the-format-0-00ie-for-hundred-100-00

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!