Re: Financial operation [Hibernate]



Arne Vajhøj wrote:
GG wrote:
I'm wondering about mapping type for ammount money in database defined as
numeric(10,2).
I have two option:

1. Mapping to BigDecimal

2. Maping to Double

I know that using BigDecimal is comfortable solution buy not most efficient and fast.
What do you think about solution witch Double ?
What are you using for financial operations ?

I hope that nobody uses double for financial operations.

Agreed.

NEVER use a float or double for financial values because arithmetic results are not always exact. In the early days people writing in MS-Basic used doubles for monetary values (MS-BASIC only had 16 bit integers, floats [9 significant digits] and doubles [17 significant digits]) and, like spreadsheets, caused periodic financial havoc. Spreadsheets also tend to use doubles.

Take note that COBOL, which was designed for business and financial use, works in the equivalent of fixed point BigDecimal - and there's a good reason for that design feature. Some dialects can do floating point but its almost never used for financial calculations. OK, maybe for currency conversions but nothing else I can think of, and even currency conversions are typically defined as fixed point calculations with the number of decimal places, the order of operations and the rounding rules legally specified.

It is almost universal to hold monetary values in the smallest currency unit, so dollar amounts are held in cents and Sterling is held in pence, with the decimal point only appearing in values intended for human input or output.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
.