Monetary Types
The monetary type stores a currency amount with fixed fractional precision.
The range shown in Table 1 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 last format but depends on the locale.
Name |
Description |
Storage Space |
Range |
---|---|---|---|
money |
Currency amount |
8 bytes |
–92233720368547758.08 to +92233720368547758.07 |
Values of the numeric, int, and bigint data types can be cast to money. Conversion from the real or double precision data type to a money value can be done by casting to numeric type first, for example:
1 2 3 4 5 |
gaussdb=# SELECT '12.34'::float8::numeric::money; money -------- $12.34 (1 row) |
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:
1 2 3 4 5 |
gaussdb=# SELECT '52093.89'::money::numeric::float8; float8 ---------- 52093.89 (1 row) |
When a money value is divided by another money value, the result is of the double precision type (that is, the digit type instead of the money type); the currency units cancel each other out in the division.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot