Why doesn't my SQL SQL SELECT statement print the decimal value?
select (4*(22/7)*3958.759*3958.759) as "Earth Area" from dual;
Prints:
Earth Area
------------
197016573
It should print 197016572.595304. Why were the numbers after the dot ignored in the output?
I am assuming you are using SQL * PLUS. The reason you don't see the rest of the number is because of the parameter value numwidth
. The default is 10, so you need to tweak it a bit, for example 30. Here's an example:
SQL> select (4*(22/7)*3958.759*3958.759) as "Earth Area" from dual;
Earth Area
------------
197016573
SQL> set numwidth 31
SQL> select (4*(22/7)*3958.759*3958.759) as "Earth Area" from dual;
Earth Area
----------------
197016572.595304
Also you can override the parameter value with numwidth
either set numformat
orcolumn format
This is SQL * Plus and has nothing to do with what is returned from the database. You can use the SQL * Plus column formatting commands to get the formats you want, for example:
SQL> select (4*(22/7)*3958.759*3958.759) as "Earth Area" from dual;
Earth Area
------------
197016573
SQL> col "Earth Area" for 99,999,999,999.9999999
SQL> /
Earth Area
-----------------------
197,016,572.5953040
Oracle documentation with more information on formatting options here .
to_char((4*(22/7)*3958.759*3958.759)), 'FM99999990D00999999999')
FM removes leading blanks. 9 represent an optional number at this position. D represents the decimal point. 0 represent the required numbers at this position.