Money data type

Hello,

Could you help me to understand the purpose of the ‘MONEY’ data type ? What is the use case ?

Because in java when I get a Map<String, Object> and want to get value from MONEY column I have to cast the value object to Integer or Double (depending on whether the value contains decimals). So it’s not always the same casting which is not practical.

Thank you.

Hi. The MONEY column is just a DECIMAL type under the hood, but with fixed decimalScale = 2.
In java it corresponds to the BigDecimal type.
Working with the money calculation you should always prefer the BigDecimal or at least the double (8 byte) type, not the integer.

Hi @oleg-vyalyh

Thank you for the clarification on the MONEY type.

However, I notice that it is possible to store an integer in a column of type double or money. This is problematic because when retrieving a value from a double or money column in Java we expect to retrieve a value of the type of the column. Currently it is therefore possible that a double column returns an integer value which generates an exception when casting the value to the real type (double) of the column. Normally the value passed to a column of type double should be converted to a double to avoid this problem.

Thank you in advance for your answer.