Currency

The Currency Data Type is used to represent a given amount of currency. It pairs a Number with a currency unit (for example "USD" or "JPY"), and a precision. The precision is used to determine how many decimal places to include.

It is important to use the Currency type rather than a Number because there are rounding errors when working with decimal Numbers. For example, the result of 0.1 + 0.2 is not 0.3 but rather 0.30000000000000004.

Example

The following example shows how $40, forty US dollars, is represented as a Currency value. Note that the currency code is "USD" and the precision is 2, so the Currency value is represented in US cents:

{
  "amount": 4000,
  "code": "USD",
  "precision": 2
}