A BigDecimal is an exact way of representing numbers. A Double has a certain precision. Working with doubles of various magnitudes (say d1=1000.0 and d2=0.001) could result in the 0.001 being dropped altogether when summing as the difference in magnitude is so large. With BigDecimal this would not happen.

The disadvantage of BigDecimal is that it's slower, and it's a bit more difficult to program algorithms that way (due to + - * and / not being overloaded).

If you are dealing with money, or precision is a must, use BigDecimal. Otherwise Doubles tend to be good enough.

I do recommend reading the javadoc of BigDecimal as they do explain things better than I do here :)

Answer from extraneon on Stack Overflow
🌐
Medium
medium.com › javarevisited › java-how-exactly-should-long-and-bigdecimal-be-used-can-you-distinguish-them-5c91c8bce18f
JAVA: How Exactly Should Long and BigDecimal Be Used? Can You Distinguish Them? | by Oliver Foster | Javarevisited | Medium
January 30, 2024 - Usage: It is used for handling ... to 2^63-1. Performance: Compared to BigDecimal, Long typically offers faster performance as it is a wrapper class for a primitive type....
🌐
Reddit
reddit.com › r/java › double vs bigdecimal in financial programming
r/java on Reddit: Double vs BigDecimal in financial programming
May 22, 2018 -

Everyone says that BigDecimal should be used when dealing with money but it’s much slower and takes more memory than double. I would think this would be especially important in high frequency low-latency applications like trading. Do people actually use BigDecimal in such systems or do they use doubles with some kind of workaround to handle the precision issue?

Edit: I do have experience working on trading and risk systems and I see doubles used much more often than BigDecimal so I was curious to see if this is more common in actual practice. Most of the systems I worked on only need precision to the penny so I wonder if that’s the reason?

Also, BigDecimal is a pain to use and code written with it look much uglier than plain doubles.

Handling money in a financial java app? Oct 1, 2017
r/javahelp
9y ago
Money calculation: Double vs BigDecimal May 24, 2022
r/javahelp
4y ago
Which is larger? Long vs Double Jan 19, 2023
r/javahelp
3y ago
Java Double Precision Aug 24, 2020
r/java
6y ago
More results from reddit.com
Discussions

java - Double vs. BigDecimal? - Stack Overflow
I have to calculate some floating point variables and my colleague suggest me to use BigDecimal instead of double since it will be more precise. But I want to know what it is and how to make most o... More on stackoverflow.com
🌐 stackoverflow.com
java - Long vs BigInteger - Stack Overflow
If Long is enough, use Long. If not, use BigInteger. ... Same way you choose between any numeric types. Is it possible for the value in question to exceed the size of a particular type? If so, use a larger type. ... @David I wouldn't say it's the case with "any numeric type". Take Double and BigDecimal... More on stackoverflow.com
🌐 stackoverflow.com
type conversion - Java BigDecimal data converting to opposite sign long - Stack Overflow
Converts this BigDecimal to a long. This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java™ Language Specification: any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big ... More on stackoverflow.com
🌐 stackoverflow.com
java - Storing dollar amounts in MySQL: INT vs LONG vs BIGINT - Stack Overflow
BigDecimal for Decimal. ... @MarcB: What are you talking about? long is an integer type in every language I've ever come across; indeed, it is an 8-byte integer in Java. More on stackoverflow.com
🌐 stackoverflow.com
May 8, 2014
🌐
Medium
medium.com › codetutorials › long-vs-bigdecimal-which-should-you-use-for-money-in-java-dfebc5e7488c
Long vs BigDecimal: Which Should You Use for Money in Java? | by Umesh Kumar Yadav | CodeTutorials | Medium
July 18, 2026 - ... If you’ve worked on payment systems, banking applications, fintech platforms, or e-commerce systems, you’ve probably encountered this discussion. Some developers insist that BigDecimal is the only correct answer. Others argue that Long ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
July 21, 2026 - Converts this BigDecimal to a long. This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java™ Language Specification: any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in a long, only the low-order 64 bits are returned.
🌐
Baeldung
baeldung.com › home › java › java numbers › convert long to bigdecimal in java
Convert Long to BigDecimal in Java | Baeldung
January 8, 2024 - When we talk about converting Long to BigDecimal, some may think both are in the Number type, so we could probably cast Long to BigDecimal like BigDecimal bd = (BigDecimal) longValue.
🌐
GitHub
github.com › gdela › java-sandbox › blob › master › articles › bigdecimal-performance.md
java-sandbox/articles/bigdecimal-performance.md at master · gdela/java-sandbox · GitHub
If it is different than Long.MIN_VALUE then it means that the value of intCompact is the unscaled value, and BigInteger is not needed for it. Otherwise BigDecimal's private field intVal will already be initialized with a BigInteger which is the unscaled value of BigDecimal. This has of course downsides, because you break encapsulation, and have to use --add-opens java.base/java.math=ALL-UNNAMED, and you are risking that your code will break with future versions of Java.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java numbers › bigdecimal and biginteger in java
BigDecimal and BigInteger in Java | Baeldung
December 16, 2024 - This method converts the double to its string representation before converting to BigDecimal, ensuring that we get the expected value every time. Just like the other Number classes (Integer, Long, Double, etc.), BigDecimal provides operations for arithmetic and comparison operations.
🌐
CodeGym
codegym.cc › java blog › java numbers › bigdecimal in java
BigDecimal in Java
January 15, 2025 - What do we need to come up with if our Very Large Number requires 100 bits? Fortunately, we don't need to invent anything. For cases such as this, Java has two special classes: BigInteger (for integers) and BigDecimal (for floating-point numbers).
🌐
Vanillajava
blog.vanillajava.blog › 2024 › 11 › overview-many-developers-consider.html
Why double Still Outperforms BigDecimal: A Decade-Long Performance Comparison
December 19, 2024 - Understanding how Core Java really works can help you write simpler, faster applications. ... Many developers consider BigDecimal the go-to solution for handling money in Java. They often claim that replacing double with BigDecimal has fixed one or more bugs in their applications.
Top answer
1 of 1
12
  1. What is the difference between BIGINT and LONG on the MySQL level?

    • java.sql.Types.BIGINT is defined as:

      The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT.

      Under Integer Types, the MySQL manual documents that its BIGINT datatype is an 8-byte (i.e. 64-bit) integer. The Java primitive datatype long (and its associated wrapper class java.lang.Long) also represents an 8-byte integer.

      Consequently, as documented under Mapping SQL and Java Types:

      The JDBC type BIGINT represents a 64-bit signed integer value between -9223372036854775808 and 9223372036854775807.

      [ deletia — outdated ]

      The recommended Java mapping for the BIGINT type is as a Java long.

    • There is no LONG constant within java.sql.Types, nor does MySQL have a LONG datatype.

    Which is more ideal for storing currencies?

    Neither. Store the dollar amount as a discrete decimal value using the NUMERIC fixed-point datatype. If you insist on storing the cent amount in an integer type, the "correct" answer depends merely on the anticipated range of values that you wish to support.

  2. What would happen if I use PreparedStatement::setLong on a BIGINT column?

    That is exactly how one should set the value of a BIGINT parameter. As documented under java.sql.PreparedStatement::setLong(int, long):

    The driver converts this to an SQL BIGINT value when it sends it to the database.

  3. That also begs the question, what happens if I use PreparedStatement::setBigDecimal on a BIGINT column?

    As documented under java.sql.PreparedStatement::setBigDecimal(int, java.math.BigDecimal):

    The driver converts this to an SQL NUMERIC value when it sends it to the database.

    So, Java will send your value to MySQL as a NUMERIC (fixed-point decimal) datatype. MySQL will then perform type conversion as described under Type Conversion in Expression Evaluation: e.g. if you are simply storing the value in a BIGINT column, the value will be cast to a BIGINT for storage. Provided that the value is in range for a BIGINT, you shouldn't notice any ill-effect (except loss of the fractional part).

🌐
Medium
medium.com › @v.yeikovych › going-big-using-biginteger-in-java-f19d397179fd
Going Big: Using BigInteger in Java
June 9, 2024 - In conclusion, while BigDecimal has traditionally been the preferred choice for floating-point arithmetic, BigInteger serves a distinct purpose in enhancing Java’s functionality. It allows for the handling of extremely large numbers beyond the capacity of primitive data types like long.
🌐
LinkedIn
linkedin.com › pulse › need-precision-why-you-should-use-javas-bigdecimal-janaka-wijerathne-vzoic
Need Precision? Why You Should Use Java’s BigDecimal and BigInteger Instead of Primitives
June 19, 2024 - In addition to `BigDecimal`, Java provides the `BigInteger` class for operations involving very large integers that exceed the capacity of primitive data types like `int` and `long`.
🌐
DEV Community
dev.to › luke_tong_d4f228249f32d86 › beyond-double-essential-bigdecimal-practices-for-accurate-financial-calculations-52m1
Beyond double: Essential BigDecimal Practices for Accurate Financial Calculations - DEV Community
May 28, 2025 - If you’ve been around software development for a bit, especially anywhere near financial applications, you’ve probably heard the golden rule: don’t use double (or float) for money. It's common knowledge, and for good reason – floating-point arithmetic can lead to precision errors that are a nightmare in finance. The go-to solution is java.math.BigDecimal.
🌐
Baeldung
baeldung.com › home › java › java numbers › java double vs. bigdecimal
Java Double vs. BigDecimal | Baeldung
January 8, 2024 - In contrast, BigDecimal presents a more extensive range of values and better precision across a wide array of values. There are also differences in memory usage. Java’s Double is more compact, which results in more efficient memory usage.
🌐
Tutorialspoint
tutorialspoint.com › java › math › bigdecimal_longvalue.htm
Java.math.BigDecimal.longValue() Method
The java.math.BigDecimal.longValue()converts this BigDecimal to an long.This conversion is analogous to the narrowing primitive conversion from double to short. Any fractional part of this BigDecimal will be discarded, and if the resulting
🌐
Frankel
blog.frankel.ch › bigdecimal-vs-double
double, BigDecimal, or Fixed-Point?
June 14, 2026 - JSR 354 defines a standard API for monetary amounts and currencies in Java, aka JavaMoney. The reference implementation, Moneta, provides two concrete types: Money: backed by BigDecimal. Maximum precision, full decimal control. FastMoney: backed by long with a fixed scale of 5 decimal places.