DataType

# Double

<div class="rst-class">

forsearch

</div>

DataType

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

A <span class="title-ref">Double</span> is an intrinsic data type. A <span class="title-ref">Double</span> is a number that can contain a decimal value, i.e., a real number. In other languages, a <span class="title-ref">Double</span> may be referred to as a <span class="title-ref">Double</span> precision floating point number. Because **Doubles** are numbers, you can perform mathematical calculations on them. **Doubles** use 8 bytes of memory. The default value of a <span class="title-ref">Double</span> is 0.0.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                | Parameters                                                                                                                                   | Returns                            | Shared |
|-------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `Equals<double.equals>`             | numValue As Double, maxUIps As `Integer</api/data_types/integer>`                                                                            | `Boolean</api/data_types/boolean>` |        |
| `FromString<double.fromstring>`     | value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                     | Double                             | ✓      |
| `IsInfinite<double.isinfinite>`     |                                                                                                                                              | `Boolean</api/data_types/boolean>` |        |
| `IsNotANumber<double.isnotanumber>` |                                                                                                                                              | `Boolean</api/data_types/boolean>` |        |
| `Parse<double.parse>`               | value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                     | Double                             | ✓      |
| `ToString<double.tostring>`         | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`, `Optional</api/language/optional>` format As `String</api/data_types/string>` | `String</api/data_types/string>`   |        |

## Method descriptions

<div id="double.equals">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Double.Equals

**Equals**(numValue As Double, maxUIps As `Integer</api/data_types/integer>`) As `Boolean</api/data_types/boolean>`

> Tests whether two `Single</api/data_types/single>` or <span class="title-ref">Double</span> numbers are equal within a specified tolerance.
>
> Use Equals rather than `=</api/language/operators/comparison/equals_operator>` when you need to determine whether two floating point numbers are close enough in value to be considered “equal.” This can be used to account for the imprecision of floating point division on computers, for example. It allows for a user-specified rounding error.
>
> For maxUIps (which must be a literal), the last position refers to the the last byte in the binary representation of the mantissa. maxUIps is the amount of difference between the last byte of the 2 numbers that is still acceptable. For example, consider these 2 numbers:
>
> ``` xojo
> 3.1415926535897932 ' last byte value is 0x18
> 3.141592653589795 ' last byte value is 0x1C
> ```
>
> A maxUIps of 3 will result in "not equal", while a maxUIps of 4 will result in "equal".
>
> More information: <https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/>
>
> Compare two values:
>
> ``` xojo
> ' 2 double values that vary by a tiny bit
> Var d1 As Double = 3.1415926535897935
> Var d2 As Double = 3.1415926535897933
>
> If d1 = d2 Then
> ' Will not get here because they are not an exact match
> End If
>
> If d1.Equals(d2, 1) Then
> ' Will get here because they are "close enough"
> End If
> ```

<div id="double.fromstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Double.FromString

**FromString**(value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Double

> Converts a String value containing a number that can be represented as a <span class="title-ref">Double</span> to a <span class="title-ref">Double</span> value.
>
> This method is `shared</api/language/shared>`.
>
> If no *locale* is specified, then `Locale.Raw<locale.raw>` is used.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> The *locale* parameter is not currently supported for Android.
>
> </div>
>
> Convert values to the <span class="title-ref">Double</span> type:
>
> ``` xojo
> Var userValue As String
> userValue = "123.45"
>
> Var d As Double
> d = Double.FromString(userValue)
>
> Var locale As New Locale("en-US")
> Var value As Double
>
> userValue = "123.45"
> value = Double.FromString(userValue, locale) ' value = 123.45
> ```

<div id="double.isinfinite">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Double.IsInfinite

**IsInfinite** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the value is infinite.

<div id="double.isnotanumber">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Double.IsNotANumber

**IsNotANumber** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the value is a Signaling NaN (sNaN). Quiet NaN (qNaN) values are not detected by this method.

<div id="double.parse">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Double.Parse

**Parse**(value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`) As Double

> Converts a String to a <span class="title-ref">Double</span> value.
>
> This method is `shared</api/language/shared>`.
>
> If no *locale* is specified, then `Locale.Raw<locale.raw>` is used.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> The *locale* parameter is not currently supported for Android.
>
> </div>
>
> Numbers are converted only if they are found at the beginning of the text. Any numbers that follow a non-numeric value are ignored. Empty text returns 0.
>
> ``` xojo
> Var d As Double
> d = Double.Parse("123ABC")
> ' d = 123
> ```

<div id="double.tostring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Double.ToString

**ToString**(locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`, `Optional</api/language/optional>` format As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Converts a <span class="title-ref">Double</span> value to a String value using the supplied locale and format.
>
> If no locale is specified, then Locale.Raw is used.
>
> Refer to [Unicode Number Format Patterns](http://unicode.org/reports/tr35/tr35-4.html#Number_Format_Patterns) for a list of formats.
>
> Convert <span class="title-ref">Double</span> values to String values:
>
> ``` xojo
> Var d As Double = 123.45
>
> Var s As String
> s = d.ToString ' s = "123.45"
>
> Var n As Double = 1239.4567
> Var s1 As String = n.ToString(Locale.Current, "#,###.##") ' s1 = 1,239.46
>
> Var n2 As Double = 12
> Var s2 As String = n.ToString(Locale.Current, "#.00") ' s2 = 12.00
> ```
>
> The format string can contain up to three sections separated by semicolons to control the output for positive, negative, and zero values independently:
>
> ``` xojo
> Var amount As Double = 1239.45
> Var s As String = amount.ToString(Locale.Current, "#,##0.00;(#,##0.00);'-'")
> ' s = "1,239.45"
>
> amount = -1239.45
> s = amount.ToString(Locale.Current, "#,##0.00;(#,##0.00);'-'")
> ' s = "(1,239.45)"
>
> amount = 0.0
> s = amount.ToString(Locale.Current, "#,##0.00;(#,##0.00);'-'")
> ' s = "-"
> ```

## Notes

<span class="title-ref">Double</span> is an IEEE <span class="title-ref">Double</span>-precision, floating-point value. This means it is speedy but has some limits for values it can contain. For more information, refer to the wikipedia page about floating point or the [Floating Point Primer blog post](https://blog.xojo.com/2015/12/10/but-its-not-precise-a-floating-point-values-primer/).

In most situations you should use `Currency</api/data_types/currency>` when dealing with monetary values.

The `VarType</api/language/vartype>` function returns a value of 5 when passed a <span class="title-ref">Double</span>.

<span class="title-ref">Double</span> literals can be written using standard decimal notation, e.g. 3.14, or using scientific notation by following the number with "e" (or "E") and a signed exponent, e.g. 1.5e10 or 6.022e23.

``` xojo
Var d As Double = 1.5e10 ' d = 15000000000.0
Var d2 As Double = 6.022e23 ' d2 = 6.022e+23
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Numerical limits

- The maximum value of a <span class="title-ref">Double</span> is: ±1.79769313486231570814527423731704357e+308
- The minimum value towards zero is: ±4.94065645841246544176568792868221372e-324

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Nan and infinity

Doubles can hold some special values described below: \* NaN (i.e. "Not a Number"): occurs if you attempted to perform an illegal mathematical operation, like getting the square root of a negative number. Any further calculation made with a NaN will lead to a NaN value. `Str</api/text/str>` or `Format</api/text/format>` methods return a string beginning with "NaN", e.g. "NaN(021)". \* Infinity: some calculations lead to an infinite result (positive or negative), e.g. Log( 0 ), or you may exceed the maximum value which can be hold. In such a case, a <span class="title-ref">Double</span> will be set to a special value, whose `Str</api/text/str>` will return "INF" (for INFinity) or "-INF" (negative INFinity). Any further calculation will lead to a NaN or infinity value.

You can test for these values using the `IsNotANumber<double.isnotanumber>` and `IsInfinite<double.isinfinite>` methods.

## Sample code

The <span class="title-ref">Double</span> data type allows you to store and manage floating point numbers.

``` xojo
Var d As Double
d = 3.141592653
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Var</api/language/var>`, `Static</api/language/static>`, `Currency</api/data_types/currency>`, `Single</api/data_types/single>` data types; `Equals</api/language/equals>`, `IsNumeric</api/language/isnumeric>`, `Mod</api/language/operators/mathematical/mod>`, `Str</api/text/str>`, `Val</api/text/val>`, `VarType</api/language/vartype>` functions; [Double precision floating point format on Wikipedia](http://en.wikipedia.org/wiki/Double_precision_floating-point_format), [Floating Point Primer](https://blog.xojo.com/2015/12/10/but-its-not-precise-a-floating-point-values-primer/) topics.

</div>
