Skip to content
Advertisement

How to show decimal value separately in PostgreSQL?

I have a table named c_price and have a column value like below in PostgreSQL.

st_price
100.25
102.25

Now need a query for below result.

st_price  | p1  | p2
----------+-----+----
100.25    | 100 | 25
102.26    | 102 | 26

Advertisement

Answer

trunc() and mod() may be used

select trunc(123.67) as dollars, trunc(mod(123.67*100,100)) as cents
dollars | cents
------: | ----:
    123 |    67

db<>fiddle here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement