📜  C#中的double关键字

📅  最后修改于: 2021-05-29 20:33:17             🧑  作者: Mango

关键字是用于某些内部过程或表示某些预定义动作的语言中的单词。它是一个关键字,用于声明一个变量,该变量可以存储从±5.0 x 10 -324到±1.7 x 10 308范围内的浮点值。它是System.Double的别名。基本上,它是64位双精度浮点数,并且具有14到15位的精度。

Double Keyword在内存中占用8个字节(64位)的空间。

句法:

double variable_name = value;

我们可以指定后缀dD来表示双精度值。同样,不使用任何后缀的浮点值也被视为双精度值。

例子:

Input: num: 1234.5678

Output: num: 1234.5678
        Size of a double variable: 8

Input: num = -67895.4322D

Output: Type of num: System.Double
        num: -67895.4322
        Size of a double variable: 8

范例1:

// C# program for the double keyword
using System;
using System.Text;
  
class geeks {
  
    static void Main(string[] args)
    {
        // variable declaration
        double num = 1234.5678;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a double variable: " + sizeof(double));
    }
}

输出:

num: 1234.5678
Size of a double variable: 8

范例2:

// C# program for the double keyword
using System;
using System.Text;
  
namespace Test {
  
class geeks {
  
    static void Main(string[] args)
    {
        // variable declaration
        double num = -67895.4322D;
  
        // to print type of variable
        Console.WriteLine("Type of num: " + num.GetType());
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a double variable: " + sizeof(double));
  
        // to print minimum & maximum value of double
        Console.WriteLine("Min value of double: " + double.MinValue);
        Console.WriteLine("Max value of double: " + double.MaxValue);
  
        // hit ENTER to exit
        Console.ReadLine();
    }
}
}

输出:

Type of num: System.Double
num: -67895.4322
Size of a double variable: 8
Min value of double: -1.79769313486232E+308
Max value of double: 1.79769313486232E+308