如何以0,00格式显示价格(即100 100,00)
HII,
我正在使用devexpress网格控件。在我的网格中有价格标签,我希望价格列以0,00格式显示….即如果我的价格是3000那么它应该显示3.000,00 …请帮助我…这是winforms,前端是c#。
DevExpress控件丰富而复杂,有很多方法可以做到这一点。
最简单的可能是设置列的显示格式,如下所示:
gridColumn.DisplayFormat.FormatString = "N2"; gridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
FormatString可以是任何.NET标准或自定义格式字符串(在MSDN或google中查找“标准数字格式字符串”,“自定义数字格式字符串”)。
对于devexpress XtraGrid,您可以使用DevExpress.Utils.FormatInfo:
DevExpress.Utils.FormatInfo fi = new DevExpress.Utils.FormatInfo(); fi.FormatType = DevExpress.Utils.FormatType.Numeric; fi.FormatString = "n2"; myColumn.DisplayFormat.Assign(fi);
如果您还想包含货币符号:
decimal price = 49.99M; string data = price.ToString("c");
货币格式取决于系统设置,有时最好明确指定精度:
double price; string text=price.ToString("N2"); // N3 for 3 digits , etc