Home > front end >  ABS() function in oracle and PostgreSQL showing different result
ABS() function in oracle and PostgreSQL showing different result

Time:02-19

Converting a code from oracle to postgres,But ABS() function showing different format result. How to get exact format as oracle.

ORACLE

SQL> select ABS(0.00) from dual;

         0
SQL> select ABS(-2.05) from dual;

      2.05
SQL> select ABS(2.50) from dual;

       2.5

Postgres

select abs(0.00)

0.00

select abs(-2.05)

2.05

select abs(2.50)

2.50 

CodePudding user response:

The difference you observe is insignificant and is just caused by a different way to display numeric data: PostgreSQL shows as many zeros as the scale of the type decrees.

If you want numbers to appear in a certain format, always format them using to_char().

CodePudding user response:

use ::REAL in postgres

use :: operator to convert decimal number containing trailing zeros to a number without additional zeros.

example:

select abs(2.50)::REAL;
  • Related