As money manipulation needs care it is really not interesting to use floating points, because arithmetic operations with them result in certain inaccuracies.
The data type recommended for this is the Bigdecimal, where you can choose the desired accuracy level. Unlike the double
and of float
, using the binary basis and having trouble keeping fractional numbers, the BigDecimal
is more appropriate due to the fact that manipulations occur through the use of decimal basis.
Note: due to the problems of imprecision already mentioned, it is always recommended to make use of the constructor using String as a parameter, as in the example:
BigDecimal bd = new BigDecimal("0.1");
you will make currency conversion?
– Math
No, I will store the values to show in tables, conducting promotions etc
– Luan R