Home > Blockchain >  Round Up and Round Down in Postgresql
Round Up and Round Down in Postgresql

Time:08-03

My value is 0.5503705629 and the expected value when Round up is 0.56 and Round down is 0.55.

Round down i could achieve by using

select round(cast( 0.5503705629 as numeric),2)::numeric(50,10)

CodePudding user response:

Welcome to SO.

Try adding a half unit to the decimal you want to round up, e.g. 0.005

SELECT 
  round(0.5503705629,2) AS down,
  round(0.5503705629 .005,2) AS up;

 down |  up  
------ ------
 0.55 | 0.56
(1 row)
  • Related