Floating Point Round Problems

Results of above code snippet

This particular problem is known as Floating Point Problem.

The reason for the Floating Point Problem is because the machine can not convert all decimal fractions into its exact binary format.

Big Decimal

Big Decimal allows you to store the numbers exactly you are trying to represent. Big Decimal comes with java.math package along with the Big Integer.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store