decimal toString format (C#)

decimal value = 16325.62m; string specifier;// 转换用格式 specifier = "G"; Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));// 显示结果: G: 16325.62 specifier = "C"; Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));// 显示结果: C: $16,325.62 specifier = "E04"; Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));// 显示结果: E04: 1.6326E+004 specifier = "F"; Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));// 显示结果: F: 16325.62 specifier = "N"; Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));// 显示结果: N: 16,325.62 specifier = "P"; Console.WriteLine("{0}: {1}", specifier, (value/10000).ToString(specifier));// 显示结果: P: 163.26 % specifier = "0,0.000"; Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));// 显示结果: 0,0.000: 16,325.620 specifier = "#,#.00#;(#,#.00#)"; Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier));// 显示结果: #,#.00#;(#,#.00#): (16,325.62)  

转换方式和结果如上述代码及显示结果

你可能感兴趣的:(c,C#)