General discussion

Locked

Problem:Insert_ display big numeric # db

By nhanaiu99 ·
Hi,
Please help. How do I insert and display a large numeric(24,6) - 18 digits to the left of decimal and six digits to the right of decimal? I used double data type to insert and display the value to and from the db2/400. Only 16 digits from the left of decimal is accurate and the rest is incorrect. For example:
the inserting value-123456789012345678.123456;
the value in db is-123,456,789,012,345,680.000000;
displaying the value is-1.2345678901234568E17.

Thank you,
Nhan Nguyen

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Problem:Insert_ display big numeric # db

by sandesh In reply to Problem:Insert_ display b ...

One way is by writing a small java program.
With JDBC, java can insert/retrieve such values as java.math.BigInteger.

The code would be something like :

...
PreparedStatement ps = con.prepareStatement("insert into TBLNAME values (?, ?, ..)");
ps.setBigInteger(1, 32546554654456);
...
ps.executeCommand();
...

Similarly for retrieval, using the "select SOMETHING from SOMETABLE where ...", the result set may be read as follows :

rs.getBigDecimal("SOMETHING");

Hope this helps.Sandesh

Collapse -

Problem:Insert_ display big numeric # db

by nhanaiu99 In reply to Problem:Insert_ display b ...

Thank you for your answer.
The problem I have is the decimal number. It's not an Integer number. Beside I had used the BigDecimal but didn't help. I had isolated the problem by inserting and selecting the values from SQL and it works fine. But when using java the number changed in the java.

Collapse -

Problem:Insert_ display big numeric # db

by nhanaiu99 In reply to Problem:Insert_ display b ...

Thank you for your answer but my question is regarding to the decimal number - there are 18 digits to the left of decimal point and 6 digits to the right of decimal point. I had tested the BigDecimal but it didn't work out either. I had isolated the problem to just java. When java read and write it shink the number as the example above.

Collapse -

Problem:Insert_ display big numeric # db

by nise_k In reply to Problem:Insert_ display b ...

Hi Nhan,

I think you must do some R&amp on BigDecimal (you did some but I suggest more).
Best bet is creating a BigDecimal Object like this :

java.math.BigDecimal bd = new java.math.BigDecimal(data).setScale(6,java.math.BigDecimal.ROUND_HALF_EVEN);

Scale should be set as per your need.

We had faced a similar problem, and the solution was this itself.


Hope it helps.

Bye
Nise

Collapse -

Problem:Insert_ display big numeric # db

by Shanghai Sam In reply to Problem:Insert_ display b ...

Thank you very much. It works!!!

Collapse -

Problem:Insert_ display big numeric # db

by nhanaiu99 In reply to Problem:Insert_ display b ...

This question was closed by the author

Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums