.Net 格式化数字

.NET Numerical Format Characters

C or c             Used to format currency. By default, the flag will prefix the local cultural symbol (a dollar sign [$] for U.S. English).
D or d             Used to format decimal numbers. This flag may also specify the minimum number of digits used to pad the value.
E or e             Used for exponential notation. Casing controls whether the exponential constant is uppercase (E) or lowercase (e).
F or f              Used for fixed-point formatting. This flag may also specify the minimum number of digits used to pad the value.
G or g            Stands for general. This character can be used to format a number to fixed or exponential format.
N or n            Used for basic numerical formatting (with commas).
X or x             Used for hexadecimal formatting. If you use an uppercase X, your hex

// Now make use of some format tags.
static void FormatNumericalData()
{
  Console.WriteLine("The value 99999 in various formats:");
  Console.WriteLine("c format: {0:c}", 99999);
  Console.WriteLine("d9 format: {0:d9}", 99999);
  Console.WriteLine("f3 format: {0:f3}", 99999);
  Console.WriteLine("n format: {0:n}", 99999);

  // Notice that upper- or lowercasing for hex
  // determines if letters are upper- or lowercase.
  Console.WriteLine("E format: {0:E}", 99999);
  Console.WriteLine("e format: {0:e}", 99999);
  Console.WriteLine("X format: {0:X}", 99999);
  Console.WriteLine("x format: {0:x}", 99999);
}

 

The value 99999 in various formats:
c   format: $99,999.00
d9 format: 000099999
f3  format: 99999.000
n   format: 99,999.00
E  format: 9.999900E+004
e  format: 9.999900e+004
X  format: 1869F
x  format: 1869f

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值