C# 十进制文字表示法中的 M 代表什么?
为了使用十进制数据类型,我必须通过变量初始化来完成此操作:
decimal aValue = 50.0M;
M 部分代表什么?
In order to work with decimal data types, I have to do this with variable initialization:
decimal aValue = 50.0M;
What does the M part stand for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如其他人所说,这意味着它是十进制文字。 然而,起源可能不是这个答案中其他地方所暗示的。 来自 C# 注解标准(ECMA 版本,而不是 MS 版本):
类似的注释提到,C# 的早期版本包括分别表示
byte
和short
文字的“Y”和“S”。 它们因不常用而被丢弃。It means it's a decimal literal, as others have said. However, the origins are probably not those suggested elsewhere in this answer. From the C# Annotated Standard (the ECMA version, not the MS version):
A similar annotation mentions that early versions of C# included "Y" and "S" for
byte
andshort
literals respectively. They were dropped on the grounds of not being useful very often.根据 C# 规范:
请注意,您可以使用大写或小写表示法。
From C# specifications:
Note that you can use an uppercase or lowercase notation.
M 指“十进制”中的第一个非二义字符。 如果不添加它,该数字将被视为双精度数。
D是双的。
M refers to the first non-ambiguous character in "decimal". If you don't add it the number will be treated as a double.
D is double.
以 M 或 m 为后缀的实数文字的类型为十进制(货币)。 例如,文字 1m、1.5m、1e10m 和 123.456M 都是十进制类型。 通过获取精确值,并在必要时使用银行舍入法舍入到最接近的可表示值,将此文字转换为十进制值。 文字中出现的任何比例都会被保留,除非该值被舍入或该值为零(在后一种情况下,符号和比例将为 0)。 因此,文字 2.900m 将被解析为符号为 0、系数为 2900、小数位数为 3 的小数。
了解有关真实文字的更多信息
A real literal suffixed by M or m is of type decimal (money). For example, the literals 1m, 1.5m, 1e10m, and 123.456M are all of type decimal. This literal is converted to a decimal value by taking the exact value, and, if necessary, rounding to the nearest representable value using banker's rounding. Any scale apparent in the literal is preserved unless the value is rounded or the value is zero (in which latter case the sign and scale will be 0). Hence, the literal 2.900m will be parsed to form the decimal with sign 0, coefficient 2900, and scale 3.
Read more about real literals
“字母 M 被选为双精度和十进制关键字之间视觉上最明显的字母。”
"The letter M was chosen as the most visually distinct letter between the double and decimal keywords."
嗯,我猜M代表尾数。 小数可以用来省钱,但并不意味着小数只用来省钱。
Well, I guess M represent the mantissa. Decimal can be used to save money, but it doesn't mean, decimal only used for money.