-1

Here is a query in PostgreSQL:

SELECT 25/8175133

This show 0 as result, while the actual value is 0.00000305805

I tried

SELECT CAST(25/8175133 AS DECIMAL)
SELECT CAST(25/8175133 AS AS DOUBLE PRECISION)

but nothing seems to work. Is there are way to show very low fraction values in our SELECT output?

ozzboy
  • 2,672
  • 8
  • 42
  • 69

4 Answers4

4

When PostgreSQL divides two integer values the result is an integer. If you want decimal places you need to include at least one operand with decimal places.

You can do:

SELECT 1.0 * 25/8175133

or:

SELECT 25.0/8175133

Result:

?column?
--------
0.000003058054223704984372
The Impaler
  • 45,731
  • 9
  • 39
  • 76
1

Postgres is trying to return to you the same type you supplied. You can resolve this like this as well:

SELECT 25.0/8175133;
Cargo23
  • 3,064
  • 16
  • 25
0
SELECT 25/8175133 :: decimal => 0.000003058054223704984372

SELECT 25/8175133 :: double precision => 3.0580542237049843e-06

SELECT 25/8175133 :: numeric => 0.000003058054223704984372
Ergest Basha
  • 7,870
  • 4
  • 8
  • 28
Edouard
  • 6,577
  • 1
  • 9
  • 20
0

Try ROUND

 Select round(25/8175133::decimal, 11);

Refer this for sample output http://sqlfiddle.com/#!17/77c08/41

Himanshu
  • 3,830
  • 2
  • 10
  • 29