aspose file tools*
The moose likes JDBC and the fly likes Problem while inserting decimal numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem while inserting decimal numbers" Watch "Problem while inserting decimal numbers" New topic
Author

Problem while inserting decimal numbers

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
When we use JDBC racle thin driver , decimal places are inserting properly.
But when we use OCI drivers for weblogic , it inserts decimal value with junk.
Eg. decimal number is .981
it is inseriting as .981000000231
How to resolve this. It should not accept junk numbers.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Anil Sable:
[...] when we use OCI drivers for weblogic , it inserts decimal value with junk. Eg. decimal number is .981 it is inseriting as .981000000231

This is not junk. It is a simple fact of life that floating point numbers have limited precision in any implementation, including Oracle's. Most numbers cannot be represented in floating point format with complete accuracy. The "junk" you are seeing is an expression of that. Often, when working with floating point numbers, you do not display them to the user to arbitrary precision, if only because the smallest few digits cannot be trusted anyway. That hides the junk.
To reduce the problem, use "double" instead of "float". They suffer from the same problems, but their far higher precision makes them less apparent.
Note that this is not a specific driver problem or Java problem. It's present at all levels - Java, driver, database. The different drivers probably process or represent floats in slightly different ways, which is why it shows up in one case and not in the other.
If, in your application, you cannot afford any rounding errors, you have to use the java.math.BigDecimal class, and a corresponding high-precision numeric type at the database level.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem while inserting decimal numbers