编程语言
首页 > 编程语言> > c#-ToString(“ 0.0 ##”)的特定于文化的等效项

c#-ToString(“ 0.0 ##”)的特定于文化的等效项

作者:互联网

我将我的应用程序更改为允许特定于文化的数字格式,因此我将例如ToString(“ 0.00”)更改为ToString(“ F2”).但是,我没有看到等效的ToString(“ 0.###”)的任何标准方法.我将如何以一种特定于文化的方式实现这一目标?

解决方法:

实际上,.格式字符串中的只是标识区域性特定的十进制分隔符的占位符,因此ToString(“ 0.###”)应该可以正常工作.千位分隔符和百分比符号%也是如此.

证明:

CultureInfo c = CultureInfo.CreateSpecificCulture("fr-FR");

Console.WriteLine(1234.567.ToString("0.###",c));

输出:

1234,567

MSDN开始(添加了强调):

The “.” custom format specifier inserts a localized decimal separator into the result string. The first period in the format string determines the location of the decimal separator in the formatted value; any additional periods are ignored.

The character that is used as the decimal separator in the result string is not always a period; it is determined by the 07001 property of the 07002 object that controls formatting.

标签:string-formatting,c
来源: https://codeday.me/bug/20191026/1939988.html