I am trying to decide which data type shall i use for a financial application.
I have read that Double
or BigDecimal
should be used. And i am confused between them.
Any help in this regard will be highly appreciated
The type-declaration character for Currency is the at (@) sign. The Currency data type is useful for calculations involving money and for fixed-point calculations in which accuracy is particularly important.
Select the cells and then select Insert > Table. Although creating a table isn't required, it'll make inserting data from the data type much easier later. With the cells still selected, go to the Data tab and select the Currencies data type.
1 Answer. Java has Currency class that represents the ISO 4217 currency codes. BigDecimal is the best type for representing currency decimal values.
You almost certainly don't want to use floating-point types (double
, float
, Double
, Float
) to handle monetary amounts, especially if you will be performing computations on them. The main reason for this is that there are many simple-looking numbers that cannot be represented exactly as a double
et al. One such number is 0.1
.
BigDecimal
is therefore a much better choice for this use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With