Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 3.35 KB

File metadata and controls

67 lines (51 loc) · 3.35 KB
title double (C# Reference)
ms.date 07/20/2015
ms.prod .net
ms.technology
devlang-csharp
ms.topic article
f1_keywords
double
double_CSharpKeyword
helpviewer_keywords
double data type [C#]
ms.assetid 0980e11b-6004-4102-abcf-cfc280fc6991
caps.latest.revision 26
author BillWagner
ms.author wiwagn

double (C# Reference)

The double keyword signifies a simple type that stores 64-bit floating-point values. The following table shows the precision and approximate range for the double type.

Type Approximate range Precision .NET Framework type
double ±5.0 × 10−324 to ±1.7 × 10308 15-16 digits xref:System.Double?displayProperty=nameWithType

Literals

By default, a real numeric literal on the right side of the assignment operator is treated as double. However, if you want an integer number to be treated as double, use the suffix d or D, for example:

double x = 3D;  

Conversions

You can mix numeric integral types and floating-point types in an expression. In this case, the integral types are converted to floating-point types. The evaluation of the expression is performed according to the following rules:

  • If one of the floating-point types is double, the expression evaluates to double, or bool in relational or Boolean expressions.

  • If there is no double type in the expression, it evaluates to float, or bool in relational or Boolean expressions.

A floating-point expression can contain the following sets of values:

  • Positive and negative zero.

  • Positive and negative infinity.

  • Not-a-Number value (NaN).

  • The finite set of nonzero values.

For more information about these values, see IEEE Standard for Binary Floating-Point Arithmetic, available on the IEEE Web site.

Example

In the following example, an int, a short, a float, and a double are added together giving a double result.

[!code-csharpcsrefKeywordsTypes#9]

C# Language Specification

[!INCLUDECSharplangspec]

See Also

C# Reference
C# Programming Guide
C# Keywords
Default Values Table
Built-In Types Table
Floating-Point Types Table
Implicit Numeric Conversions Table
Explicit Numeric Conversions Table