DataType

# Currency

<div class="rst-class">

forsearch

</div>

DataType

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

## Description

A a decimal number that holds 15 digits to the left of the decimal point and 4 digits to the right. The default value of a <span class="title-ref">Currency</span> is 0.0.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                              | Parameters                                                                                               | Returns                          | Shared |
|-----------------------------------|----------------------------------------------------------------------------------------------------------|----------------------------------|--------|
| `FromString<currency.fromstring>` | value As `String</api/data_types/string>`, locale As `Locale</api/os/locale>` = `Nil</api/language/nil>` | Currency                         | ✓      |
| `ToString<currency.tostring>`     | locale As `Locale</api/os/locale>` = `Nil</api/language/nil>`                                            | `String</api/data_types/string>` |        |

## Method descriptions

<div id="currency.fromstring">

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

</div>

<div class="rst-class">

forsearch

</div>

Currency.FromString

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

> Converts a String value containing a number that can be represented as a <span class="title-ref">Currency</span> to a <span class="title-ref">Currency</span> value.
>
> This method is `shared</api/language/shared>`.
>
> If no locale is specified, then Locale.Raw is used.
>
> If *value* cannot be converted to a <span class="title-ref">Currency</span> (because it contains non-numeric characters, for example), then a `RuntimeException</api/exceptions/runtimeexception>` is raised.
>
> Convert values to the <span class="title-ref">Currency</span> type:
>
> ``` xojo
> Var userValue As String
> userValue = "123.45"
>
> Var c As Currency
> c = Currency.FromString(userValue)
>
> Var locale As New Locale("en-US")
> Var value As Currency
>
> userValue = "$123.45"
> value = Currency.FromString(userValue, locale) ' value = 123.45
> ```

<div id="currency.tostring">

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

</div>

<div class="rst-class">

forsearch

</div>

Currency.ToString

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

> Converts a <span class="title-ref">Currency</span> value to a String value using the specified locale.
>
> To display the <span class="title-ref">Currency</span> symbol, you need to pass in a locale. The <span class="title-ref">Currency</span> symbol is displayed before or after the number as specified by the locale settings.
>
> If no locale is specified, then Locale.Raw is used.
>
> Convert <span class="title-ref">Currency</span> to Text:
>
> ``` xojo
> Var c As Currency = 123.45
>
> Var s As String
> s = c.ToString ' s = "123.45"
> ```
>
> In order to display the <span class="title-ref">Currency</span> symbol you need to provide a locale:
>
> ``` xojo
> Var c As Currency = 123.45
>
> Var s As String
> Var locale As New Locale("en-US")
> s = c.ToString(locale) ' s = $123.45
> ```
>
> This code displays a value using French Canadian locale with the <span class="title-ref">Currency</span> symbol after the number:
>
> ``` xojo
> Var c As Currency = 123.45
>
> Var s As String
> Var locale As New Locale("fr-CA")
> s = c.ToString(locale) ' s = 123,45 $
> ```

## Notes

<span class="title-ref">Currency</span> can contain values from -922337203685477.5808 to 922337203685477.5807. It uses 8 bytes.

<span class="title-ref">Currency</span> is a 64-bit fixed-point decimal. This means that <span class="title-ref">Currency</span> does not have some of the rounding issues that are inherent in floating-point numbers stored in Double.

Use <span class="title-ref">Currency</span> instead of Double when storing monetary values. Since Double is a standard double-precision floating-point number, it is unable to store some specific decimal values. The <span class="title-ref">Currency</span> type avoids these issues, which can be particularly important with rounding and when dealing with money.

## Sample code

Assign a value to a <span class="title-ref">Currency</span> variable:

``` xojo
Var c As Currency
c = 42.56
```

## Compatibility

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

<div class="seealso">

`Double</api/data_types/double>` data type

</div>
