Csharp/CSharp Tutorial/Data Type/double
Содержание
comparison between double values
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string comparison;
Console.WriteLine("Enter a number:");
double var1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter another number:");
double var2 = Convert.ToDouble(Console.ReadLine());
if (var1 < var2)
comparison = "less than";
else {
if (var1 == var2)
comparison = "equal to";
else
comparison = "greater than";
}
Console.WriteLine("The first number is {0} the second number.",
comparison);
}
}
double const
To declare a variable of type double, use a statement similar to that shown here:
double result;
Double: Epsilon, Positive/Negative Infinity and Max/Min Value
using System;
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("double.Epsilon: {0}", double.Epsilon);
Console.WriteLine("double.PositiveInfinity: {0}",double.PositiveInfinity);
Console.WriteLine("double.NegativeInfinity: {0}",double.NegativeInfinity);
Console.WriteLine("double.MaxValue: {0}",double.MaxValue);
Console.WriteLine("double.MinValue: {0}",double.MinValue);
}
}
double.Epsilon: 4.94065645841247E-324 double.PositiveInfinity: Infinity double.NegativeInfinity: -Infinity double.MaxValue: 1.79769313486232E+308 double.MinValue: -1.79769313486232E+308
Exponential Notation
class MainClass
{
static void Main()
{
System.Console.WriteLine(6.023E23f);
}
}
Specifying a Literal double
class MainClass
{
static void Main()
{
System.Console.WriteLine(1.618);
}
}