首页 > 代码库 > decimal.tostring()格式
decimal.tostring()格式
nt/Decimal.ToString 方法 (String, IFormatProvider)
decimal value = http://www.mamicode.com/16325.62m; string specifier; CultureInfo culture;
// Use standard numeric format specifiers. specifier = "G";
culture = CultureInfo.CreateSpecificCulture("eu-ES");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 16325,62
Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture));
// Displays: 16325.62
specifier = "C";
culture = CultureInfo.CreateSpecificCulture("en-US");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: $16,325.62
culture = CultureInfo.CreateSpecificCulture("en-GB");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 16,325.62
specifier = "E04";
culture = CultureInfo.CreateSpecificCulture("sv-SE");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 1,6326E+004
culture = CultureInfo.CreateSpecificCulture("en-NZ");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 1.6326E+004
specifier = "F";
culture = CultureInfo.CreateSpecificCulture("fr-FR");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 16325,62
culture = CultureInfo.CreateSpecificCulture("en-CA");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 16325.62
specifier = "N";
culture = CultureInfo.CreateSpecificCulture("es-ES");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 16.325,62
culture = CultureInfo.CreateSpecificCulture("fr-CA");
Console.WriteLine(value.ToString(specifier, culture));
// Displays: 16325,62
specifier = "P";
culture = CultureInfo.InvariantCulture;
Console.WriteLine((value/10000).ToString(specifier, culture));
// Displays: 163.26 %
culture = CultureInfo.CreateSpecificCulture("ar-EG");
Console.WriteLine((value/10000).ToString(specifier, culture));
// Displays: 163.256 %
decimal aa = Convert.ToDecimal("99999.99999");
string bb = aa.ToString("N5");
得到 bb=9,999.99999
12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16进制)
12345.ToString("p"); //生成 1,234,500.00%