Category Image Numeric Type for Money in MySQL and EOModeler


Use DECIMAL instead of DOUBLE for values that require exact presicion and decimal places. Always use a precision (number of total digits required before AND after the decimal point, including an extra one for negative numbers) and use a scale to tell MySQL how many decimal places of accuracy you need. Map this type to java BigDecimal in the java.math package.

DECIMAL is ideal for monetary/currency values.

See here for explanation from MySQL website:
http://www.mysql.com/doc/en/Numeric_types.html

So in EOModeler, you would use BigDecimal as the java class (make sure you import java.math.* in the entity class since BigDecimal and BigInteger are in the java.math package. For more see the BigDecimal API at suns website . For column type use DECIMAL and specify a precision and scale.

Some mailing lists have had developers complain about no MySQL equivalent for java's BigDecimal, but in reality DECIMAL is it! Some list contributors say they have "solved" this by using NSDecimal and EOModel Value of d, but as Using EOModeler clearly states on page 56, a Value type set to d is still a DOUBLE.

So in summary, the EOModeler prototype for monetary values are:
Java Class: BigDecimal
External Type: DECIMAL
Value: B
Precision: <your choice ... I use 18>
Scale: <your choice ... I use 7>

Posted: Wednesday - January 14, 2004 at 12:42 PM        


Published by