开发者

Remove (.) from decimal values in postgres

开发者 https://www.devze.com 2023-04-11 03:31 出处:网络
I want to remove . from all decimal value from my query output like if i use select(32.00) output should come 3200

I want to remove . from all decimal value from my query output like if i use

select(32.00) output should come 3200
select(32.50) output should come 3250
select(32.05) output should come 3205

Is there is any function 开发者_如何学Pythonpresent to give me this output i dont want 3200.00 as output if anyone know plz tell me how ?


You could multiply by 100 and cast to an integer:

=> select cast(32.00*100 as integer);
 int4 
------
 3200

That will give you an integer. If your values aren't the decimal(n,2) that they appear to be, then you might want to pull out round, floor, or ceil to make your desired rounding or truncation explicit:

=> select floor(23.025 * 100), ceil(23.025 * 100), round(23.025 * 100);
 floor | ceil | round 
-------+------+-------
  2302 | 2303 |  2303


You could try:

SELECT replace(CAST(your_field AS text),'.','')
FROM your_table
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号