0

I am trying to retrieve STDDEV of a decimal value from Db2 for z/OS table. I use the below SQL.

            // Execute a query and generate a ResultSet instance
            rs = stmt.executeQuery("SELECT STDDEV(SALARY) FROM DSN8910.EMP"
                    + " WHERE WORKDEPT = 'A00' ");  
                        while (rs.next()) {
                hStdDev         = rs.getBigDecimal(1);
                System.out.println("hStdDev " + hStdDev);
            }

I get different results in SPUFI and while using JDBC.

Using SPUFI:

+0.9742432961021595E+04

Using JDBC:

9742.432961021594

I tried using getString, getFloat. But all of them yields a same result.

Two questions:

  1. How can I display it in an exponential form ? Same as SPUFI result.
  2. The last digit is not rounded off. how can I round off ?
  • 1
    Different default Display Formats. – mao May 05 '23 at 10:56
  • The closest I think you can get with the least amount of work is `String.format("%1.15E", hStdDev);` - but this gives `9.742432961021594E+03` - so not exactly what you want - and somewhat inflexible (hard-coded `15`). – andrewJames May 05 '23 at 14:06
  • Otherwise, see [How to express numbers in scientific notation in java?](https://stackoverflow.com/q/19984040/12567365) and similar questions. I think it's uncommon to see [scientific notation](https://en.wikipedia.org/wiki/Scientific_notation) where the value begins with `0.` and where positive numbers have a plus sign. Maybe someone else can provide a better approach. – andrewJames May 05 '23 at 14:06
  • Thank you. I was able to achieve it using String.format. :) – Jaya sakthivel May 30 '23 at 13:13

0 Answers0