C# 字符串的货币形式
输出货币形式
当前语言中的货币形式
货币形式采用"C"或"c"符号。
string a = string.Format("{0:c1}", 150.39); // ¥150.4
string b = string.Format("{0:c}", 20.5); // ¥20.50
string c = string.Format("{0:c0}", 83.71); // ¥84
多种语言的货币形式
System.Globalization命名空间下的CultureInfo类,封装了各地语言文化信息。
decimal val = 3960.12M;
CultureInfo cn = CultureInfo.GetCultureInfoByIetfLanguageTag("zh-CN");
CultureInfo tw = CultureInfo.GetCultureInfoByIetfLanguageTag("zh-TW");
CultureInfo us = CultureInfo.GetCultureInfoByIetfLanguageTag("en-US");
CultureInfo mo = CultureInfo.GetCultureInfoByIetfLanguageTag("zh-MO");
CultureInfo hk = CultureInfo.GetCultureInfoByIetfLanguageTag("zh-HK");
CultureInfo jp = CultureInfo.GetCultureInfoByIetfLanguageTag("ja-JP");
Console.WriteLine("原数值:{0}\n", val);
Console.WriteLine("人民币:{0}", val.ToString("C", cn));
Console.WriteLine("台币:{0}", val.ToString("C", tw));
Console.WriteLine("美元:{0}", val.ToString("C", us));
Console.WriteLine("澳元:{0}", val.ToString("C", mo));
Console.WriteLine("港币:{0}", val.ToString("C", hk));
Console.WriteLine("日元:{0}", val.ToString("C", jp));
Console.Read();
结果:
原数值:3960.12
人民币:¥3,960.12
台币:NT$3,960.12
美元:$3,960.12
澳元:MOP3,960.12
港币:HK$3,960.12
日元:¥3,960
本文来自博客园,作者:一纸年华,转载请注明原文链接:https://www.cnblogs.com/nullcodeworld/p/18210643