[英].NET default formatting of decimal
为什么这2个代码有不同的行为?
decimal test = 53M;
var label = "Some thing " + test + " other thing";
Console.WriteLine(label);
test = 53.00M;
label = "Some thing " + test + " other thing";
Console.WriteLine(label);
显示:
一些东西53其他东西
东西53,00其他
如果我们咨询Decimal
二进制表示形式
https://docs.microsoft.com/en-us/dotnet/api/system.decimal.getbits?view=netframework-4.8
小数的二进制表示形式包括一个1位符号,一个96位整数和一个比例因子 ,该比例因子用于将整数除以并指定整数的哪一部分为小数。 比例因子隐式为数字10,升至0到28范围内的指数。
( 黑体字是我的,德米特里·拜琴科)
我们可以轻松地解释53M
和53.00M
之间的区别 :
53M == {Integer Number: 53; Scaling Factor: 0} == 53 / 10**0
53.00M == {Integer Number: 5300; Scaling Factor: 2} == 5300 / 10**2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.