Skip to Main Content

Java and JavaScript in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Loss of precision converting from NUMERIC to float.

Matthew MorrisNov 15 2017 — edited Nov 16 2017

In querying data from a NUMBER column in the database that contains currency information (i.e. two decimal places of data), I am using the java FLOAT type as the destination variable type.  On compilation, I get a warning: "Warning: Loss of precision possible in conversion from NUMERIC to column float rate."  The warning isn't misplaced, because I am, and it's causing a problem.  For example, 27.55 becomes 27.5499992370605.

What variable type should I be using for currency-type data? If FLOAT is correct, is there a way to fix the precision problem (other than simply rounding the result to two decimal places after the fact)?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2017
Added on Nov 15 2017
1 comment
560 views