It is known that java floating point primitive values are not to be used when arbitrary precision is required. Goetz explained the problem in his excellent article.
Imagine we need to achieve arbitrary precision in a certain project and we don’t have a BigDecimal class (because it is not available in the API, e.g.: JavaME) nor have time to develop a custom implementation. Provided we know in advance that only a relatively small precision is required (2 to 4 decimals), would it be possible to implement a 100% reliable emergency workaround using float and double types and a rounding function? And if so, which function in the API could be used?
In case this function were not available, but still you think it could address the problem, how complex would it be to implement it?
No, it wouldn’t be possible because some values can’t be represented using floating point arithmetic.
0.1is the simplest example.