8.2. Monetary Types

|     8.2. Monetary Types     |                   |                     |                  |                                |
|:---------------------------:|-------------------|---------------------|------------------|--------------------------------|
|[Prev](datatype-numeric.html)|[Up](datatype.html)|Chapter 8. Data Types|[Home](index.html)| [Next](datatype-character.html)|

---

## 8.2. Monetary Types

 The `money` type stores a currency amount with a fixed fractional precision; see [Table 8.3](datatype-money.html#DATATYPE-MONEY-TABLE). The fractional precision is determined by the database's [lc\_monetary](runtime-config-client.html#GUC-LC-MONETARY) setting. The range shown in the table assumes there are two fractional digits. Input is accepted in a variety of formats, including integer and floating-point literals, as well as typical currency formatting, such as `'$1,000.00'`. Output is generally in the latter form but depends on the locale.

**Table 8.3. Monetary Types**

| Name  |Storage Size|  Description  |                     Range                     |
|-------|------------|---------------|-----------------------------------------------|
|`money`|  8 bytes   |currency amount|\-92233720368547758.08 to +92233720368547758.07|

 Since the output of this data type is locale-sensitive, it might not work to load `money` data into a database that has a different setting of `lc_monetary`. To avoid problems, before restoring a dump into a new database make sure `lc_monetary` has the same or equivalent value as in the database that was dumped.

 Values of the `numeric`, `int`, and `bigint` data types can be cast to `money`. Conversion from the `real` and `double precision` data types can be done by casting to `numeric` first, for example:

```
SELECT '12.34'::float8::numeric::money;

```

 However, this is not recommended. Floating point numbers should not be used to handle money due to the potential for rounding errors.

 A `money` value can be cast to `numeric` without loss of precision. Conversion to other types could potentially lose precision, and must also be done in two stages:

```
SELECT '52093.89'::money::numeric::float8;

```

 Division of a `money` value by an integer value is performed with truncation of the fractional part towards zero. To get a rounded result, divide by a floating-point value, or cast the `money` value to `numeric` before dividing and back to `money` afterwards. (The latter is preferable to avoid risking precision loss.) When a `money` value is divided by another `money` value, the result is `double precision` (i.e., a pure number, not money); the currency units cancel each other out in the division.

---

|[Prev](datatype-numeric.html)|[Up](datatype.html)| [Next](datatype-character.html)|
|:----------------------------|:-----------------:|-------------------------------:|
|     8.1. Numeric Types      |[Home](index.html) |      8.3. Character Types      |

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>