下面的代码适用于小数分隔符,这意味着,对于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));
答案 0 :(得分:4)
您需要使用包含千位分隔符的格式字符串。
E.g。一个standard format string:
dec.ToString("N2", portuguese);
dec.ToString("#,###.00", portuguese);
答案 1 :(得分: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