Reputation: 29985
I'm using MONEY type for currency data in my Postgres table. When I select data, postgres formats values according to system's lc_monetary
setting.
I would like to get rid of currency symbol in the query result without using explicit type casts (I'm using Laravel's query builder currently. Type casts will require raw queries).
Is there a way to setup lc_monetary
config setting so that currency values in query results are formatted exactly like simple floats with 2-digit precision and without thousands separator (so that I would be able to use it as a string/float in my PHP code)?
Upvotes: 3
Views: 4168
Reputation: 1505
Is select money_column/1::money safe...
According to the doc the result of dividing by money is double precision.... (The currency cancels out).
Upvotes: 0
Reputation: 2358
Most people I have talked to reccommend not using the money type. Typically MONEY types get output as strings by your local implementation becuase of the LC_MONETARY formatting. Most people (myself included) recommend using a NUMERIC for your monetary values.
Also you mentioned placing your money values in a float. Floats on computers have rounding errors naturally and can cause issues with monetary amounts, so be careful.
In Python we use the decimal class when we need to do math on money, I assume that PHP has something similar.
Upvotes: 2