This topic has not yet been rated - Rate this topic

# double (Visual J#)

Visual Studio 2005

The double keyword denotes 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

double

-1.7E308 to 1.7E308

15-16 digits

By default, a real numeric literal on the right-hand 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;
```

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 boolean in the case of relational or Boolean expressions).

• If there is no double type in the expression, it evaluates to float (or boolean in the case of 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 on these values, refer to the IEEE Standard for Binary Floating-Point Arithmetic, available on the Web site http://www.ieee.org/portal/index.jsp.

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

```// keyword_double.jsl
// Mixing types in expressions
public class MixedTypes
{
public static void main(String[] args)
{
int x = 3;
float y = 4.5f;
short z = 5;
double w = 1.7E+3;
// Double result.
System.out.println("The sum is " + (x + y + z + w));
}
}
```
`The sum is 1712.5`
Did you find this helpful?
(1500 characters remaining)