C#--格式化数值数据

如果数值数据需要更精细的格式化,每一个占位符都可以包含不同的格式字符,下表展示了核心格式化选项。

image
 

下面用一个例子来说明。

 

 1 namespace LearningCSharp
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             FormatNumber();
 8             Console.ReadKey();
 9             
10         }
11 
12         static void FormatNumber()
13         {
14             Console.WriteLine("The value 99999 in different ways:");
15             Console.WriteLine("c format : {0:c}",99999);
16             Console.WriteLine("d9 format : {0:d9}",99999);
17             Console.WriteLine("f format : {0:f3}", 99999);
18             Console.WriteLine("g format : {0:g}", 99999);
19 
20             Console.WriteLine("n format : {0:n}",99999);
21             Console.WriteLine("E format : {0:E}",99999);
22             Console.WriteLine("e format : {0:e}",99999);
23             Console.WriteLine("X format : {0:X}",99999);
24             Console.WriteLine("x format : {0:x}",99999);
25         }
26     }
27 }

 

 
 

image

如果想要了解更多关于.net字符串的格式化,可以查阅.net framework 文档的Formatting Type主题。

转载于:https://www.cnblogs.com/tamarous/p/4321024.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值