0

下面的代码适用于小数分隔符,这意味着,对于 pt-pt 它呈现“,”,而 en-us 它呈现“。”

如何使用千位分隔符完成相同的行为?

        decimal dec = Convert.ToDecimal(20000.01);

        IFormatProvider portuguese = new System.Globalization.CultureInfo("pt-pt");
        IFormatProvider english = new System.Globalization.CultureInfo("en-us");

        Console.WriteLine(dec.ToString(portuguese));
        Console.WriteLine(dec.ToString(english));
4

2 回答 2

4

您需要使用包含千位分隔符的格式字符串。

例如标准格式字符串

dec.ToString("N2", portuguese);

自定义格式字符串

dec.ToString("#,###.00", portuguese);
于 2012-10-24T08:15:58.457 回答
1

这无疑是在黑暗中拍摄的。

decimal dec = Convert.ToDecimal(20000.01);

IFormatProvider portuguese = new System.Globalization.CultureInfo("pt-pt");
IFormatProvider english = new System.Globalization.CultureInfo("en-us");

Console.WriteLine(dec.ToString({0:C},portuguese)); //tell it that its currency
Console.WriteLine(dec.ToString(({0:C},english));   //tell it that its currency
于 2012-10-24T04:04:58.090 回答