Java – data type used to manipulate currency

I'm trying to decide which data type to use for financial applications

I've read that double or BigDecimal should be used I was confused between them Any help in this regard will be highly appreciated

Solution

You almost certainly don't want to use floating point types (double, float, double, float) to process currency amounts, especially if you're going to perform calculations on them The main reason is that many seemingly simple numbers can not be completely expressed as double, etc One such number is 0.1

Therefore, BigDecimal is a better choice for this use case

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>