Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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!

Use of BigDecimal and the storing of Currency values

575942Jun 5 2007 — edited Jun 21 2007
Hi,

I am using JHS 10.3.1, JDev 10.3.1.2 and MS-SQL 2003.

according to Sun (http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html), BigDecimal should be used to store currency values. Double and float do not have the correct precision to hold currency values. I get an error when I use the following setup with BigDecimal:

EO Attribute Type: BigDecimal
JHS java Type: BigDecimal
DB Data Type: Numeric(20,3)
Result: Cannot save a value into the field. If an integer value is entered (e.g. 1) the following error is thrown:

Could not convert instance:1 of type:class java.lang.Long into type:class java.math.BigDecimal

If a double value (e.g. 1.2) is entered the following error is thrown:

Could not convert instance:1.2 of type:class java.lang.Double into type:class java.math.BigDecimal

Why is it trying to convert java.lang.Long and java.lang.Double into a bigDecimal when the java type in JHS is already set to BigDecimal?

I have tried different java types in JHS and the only one that works is String ie:
EO Attribute Type: BigDecimal
JHS java Type: String
DB Data Type: Numeric(20,3)

What exactly is the Java type used for in JHS? as it doesnt seem to have any direct correlation between its type and the type of data that is entered in the field. Will I run into more problems down the line by using a JHS java type of String for a numeric input field?

Any help or advice is much appreciated
Bar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 19 2007
Added on Jun 5 2007
3 comments
3,726 views