我有一个名为c_price
的表,在PostgreSQL中有一个如下所示的列值。
st_price |
---|
100.25 |
102.25 |
trunc()
和mod()
可以使用
select trunc(123.67) as dollars, trunc(mod(123.67*100,100)) as cents
美元|美分------:|----:123|67
db<gt;小提琴这里
您可以尝试以下操作-DEMO HERE
select st_price,
st_price::int as p1,
substring((st_price-st_price::int)::text,position('.' in (st_price-st_price::int)::text)+1) as p2
from tablename
我认为最简单的方法是使用:
select st_price, trunc(st_price)as p1, st_price % 1 as p2
from c_price;
当与1
的第二个自变量一起使用时,模运算符%
返回数字的小数部分。
这里有一个db<gt;不停摆弄