码迷,mamicode.com
首页 > 其他好文 > 详细

decimal.tostring()格式

时间:2014-06-24 09:52:33      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ext   color   string   os   

nt/Decimal.ToString 方法 (String, IFormatProvider)

 

decimal value = 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%

decimal.tostring()格式,布布扣,bubuko.com

decimal.tostring()格式

标签:style   blog   ext   color   string   os   

原文地址:http://www.cnblogs.com/wayne-ivan/p/3799180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!