小数 ###
C#十进制关键字 (C# decimal keyword)
In C#, decimal is a keyword which is used to declare a variable that can store a floating type value (value with the precision) between the range of ±1.0 x 10-28 to ±7.9228 x 1028. decimal keyword is an alias of System.Decimal.
在C#中, 十进制是一个关键字,用于声明一个变量,该变量可以存储介于±1.0 x 10 -28到±7.9228 x 10 28范围内的浮点型值(精度值)。 十进制关键字是System.Decimal的别名。
It occupies 16 bytes (128 bits) in the memory.
它在内存中占用16个字节(128位)。
Note: To represent a decimal value, we use m or M as a suffix with the literal.
注意:为了表示一个十进制值,我们使用m或M作为文字的后缀。
Syntax:
句法:
decimal variable_name = value;
It can store the value between the range of ±1.0 x 10-28 to ±7.9228 x 1028.
它可以存储介于±1.0 x 10 -28到±7.9228 x 10 28之间的值 。
C#代码演示小数关键字的示例 (C# code to demonstrate example of decimal keyword)
Here, we are declaring a decimal variable num, initializing it with the value 5610.2361m and printing its value, type and size of a decimal type variable.
在这里,我们声明一个十进制变量num ,使用值5610.2361m对其进行初始化,并打印其值,类型和十进制类型变量的大小。
using System;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
//char variable declaration
decimal num = 5610.2361m;
//printing value
Console.WriteLine("num: " + num);
//printing type of variable
Console.WriteLine("Type of num: " + num.GetType());
//printing size of a decimal
Console.WriteLine("Size of a decimal variable: " + sizeof(decimal));
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
num: 5610.2361
Type of num: System.Decimal
Size of a decimal variable: 16
翻译自: https://www.includehelp.com/dot-net/decimal-keyword-in-c-sharp.aspx
小数 ###