cover image

Never Trust Float & Double with Currency in Java

Introduction The float and double are probably your go-to data types for floating-point numbers, especially if you are new to Java. It’s fine unless you’re using these types for storing precise values such as currency. Even the Java documentation advises against using these types for such values. You are welcome to look it up. Understanding the Problem 95% of the folks out there are completely clueless about floating-point. — James Gosling, Sun Fellow, Java Inventor (February 28, 1998)1 To understand the problem, let’s look at an example first....

August 8, 2021 · 8 min · Ayon Khan