且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用类型转换器转换成具体的双重文化?

更新时间:2023-01-01 10:09:07

DoubleConverter TypeDescriptor.GetConverter中获得的(typeof运算(双) )结束跌宕调用 Double.Parse 以下参数:

The DoubleConverter that is obtained from TypeDescriptor.GetConverter(typeof(double)) end ups calling Double.Parse with the following arguments:

Double.Parse(
    "2,999.95", 
    NumberStyles.Float, 
    (IFormatProvider)culture.GetFormat(typeof(NumberFormatInfo)));

问题是, NumberStyles.Float 不会让千位分隔符,这就是为什么你所得到的问题。您可以在 Microsoft连接提出这样或看其他人有同样的问题。

The problem is that NumberStyles.Float does not allows thousands separators and that's why you are getting the problem. You can submit this on Microsoft Connect or see if anybody else had the same problem.

如果 Double.Parse 被称为还与 NumberStyles.AllowThousands 不会出现问题。

If Double.Parse is called also with NumberStyles.AllowThousands the problem would not occur.

Double.Parse(
    "2,999.95", 
    NumberStyles.Float | NumberStyles.AllowThousands, 
    (IFormatProvider)culture.GetFormat(typeof(NumberFormatInfo)));