Monetary Types#
Name |
Storage Size |
Description |
Range |
|---|---|---|---|
money |
8 bytes |
currency amount |
-92233720368547758.08 to +92233720368547758.07 |
money stores currency amounts with a fixed fractional precision.
The lc_monetary setting determines the locale to use for formatting monetary amounts.
Input for money is accepted in a variety of numeric formats, including typical currency formatting such as ‘$25’. Output depends on locale.
mydb=> SET lc_monetary='sw_KE.utf8';
SET
mydb=> SELECT '25000'::money;
money
--------------
Ksh25,000.00
(1 row)
NOTE: Since the output is locale-sensitive, it might not work to load
moneydata into a database that has a different setting oflc_monetary.Before restoring a dump into a new database, make sure
lc_monetaryhas the same or equivalent value as in the database that was dumped.
numeric, int and bigint types can be directly cast to money, but real and double precision have to be cast to numeric first.
A money value can be cast to numeric without loss of precision. Conversion to other types involves intermediate conversion to numeric, and could potentially lose precision.
Division of a money value with an int involves truncation of the fractional part towards zero. To avoid losing precision, cast the value to numeric before dividing and back to money afterwards.
When a money value is divided by another money value, the result is double pecision and not money. The currency units cancel each other.