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
posted 14 years ago
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