BigInteger is capable of holding far bigger numbers than Long. BigInteger seems capable of holding (2 ^ 32) ^ Integer.MAX_VALUE, though that depends on the implementation (and, even if truly unbounded in the implementation, there will eventually be a physical resource limit) See explanation here.

The range of Long is [-9,223,372,036,854,775,808, +9,223,372,036,854,775,807].

Long will perform better than BigInteger so it really depends on what the size of your values will be. If they would all fall under Long's max value, it makes no sense not to use Long. If any would be bigger than the Long max value, you pretty much have to use BigInteger.

Answer from AHungerArtist 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 - Range: The range of Long is from -2^63 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.

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

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
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
optimization - What to do with Java BigDecimal performance? - Stack Overflow
I don't see any reason to be using BigDecimal. ... Yes, the precision of double is more than sufficient. I do such things too, end it works perfectly unless I forget to round and the customer sees something like -1e-13 where they expect a non-negative result. 2012-08-04T21:35:46.993Z+00:00 ... I have since designed three different trading systems for different funds and used double for prices or long ... More on stackoverflow.com
🌐 stackoverflow.com
type conversion - Java BigDecimal data converting to opposite sign long - Stack Overflow
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 ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - Some developers insist that BigDecimal is the only correct answer. Others argue that Long is faster, simpler, and production-proven.
🌐
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.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
July 21, 2026 - The scale of the BigDecimal is zero. ... Translates a long into a BigDecimal, with rounding according to the context settings.
🌐
GitHub
github.com › gdela › java-sandbox › blob › master › articles › bigdecimal-performance.md
java-sandbox/articles/bigdecimal-performance.md at master · gdela/java-sandbox · GitHub
Only when the unscaled value becomes too big to fit in a long, they create the BigInteger object to keep the unscaled value there. Internally this is called that the BigDecimal has been inflated. But the new BigDecimal(BigInteger unscaledValue, int scale) constructor always creates BigDecimal in the inflated form, even if the unscaled value would fit in a long.
Find elsewhere
🌐
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 - Other useful methods include subtractExact(), multiplyExact(), incrementExact(), decrementExact(), and toIntExact() (for converting long to int safely). Using these methods makes your code more robust by failing fast when an overflow occurs. Working with numbers in software, especially when money or critical quantities are involved, requires diligence. BigDecimal is a powerful tool, but like any tool, you need to understand its intricacies.
🌐
Frankel
blog.frankel.ch › bigdecimal-vs-double
double, BigDecimal, or Fixed-Point?
June 14, 2026 - Money: backed by BigDecimal. Maximum precision, full decimal control. FastMoney: backed by long with a fixed scale of 5 decimal places.
🌐
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`.
🌐
Vanillajava
blog.vanillajava.blog › 2024 › 11 › overview-many-developers-consider.html
Why double Still Outperforms BigDecimal: A Decade-Long Performance Comparison
December 19, 2024 - Does this give you different results? For the most part, double provides 15 digits of precision, which is more than enough for typical monetary values. If these prices had 17 digits, BigDecimal might be more appropriate.
🌐
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.
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).

🌐
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).
🌐
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.
🌐
LinkedIn
linkedin.com › pulse › why-we-should-use-bigdecimal-instead-double-java-financial-ismail
Why we should use BigDecimal instead double in java for financial systems
May 17, 2022 - This time we got correct outputs for both Example 5.1 & 5.2 . Hence we should always try to use String constructor of BigDecimal class as much as possible where each digit of decimal part are important.
Top answer
1 of 4
17

From: http://www.javamex.com/tutorials/math/BigDecimal_BigInteger_performance.shtml

Note that a BigDecimal is essentially a wrapper around a BigInteger that "remembers where the decimal point is".

Because of the way we are used to dealing with numbers, as humans, we may have to "think a bit more" when calculating with non-integers by hand compared to integers (e.g. we may have learnt the 7 times table by heart to speed up certain calculations, but probably not the .7 times table). But to a computer implementation, it is essentially no more effort to manipulate non-integers than it is integers, and so on the whole, methods on BigDecimal tend to perform similarly to analogous methods on BigInteger.

2 of 4
4

I know the title of your question states "Performace of BigDecimal vs. BigInteger and BigDecimal" but one of your questions states "How about using only primitive data types and BigInteger or only BigInteger to make ". Well here is what I recommend:

If you need accuracy, precision and you have large numbers to work with such as huge financial data then it may be best to use BigDecimal and BigInteger instead of primitive types. Few other characteristics of BigDecimal and BigInteger are also:

  1. Both are from immutable objects.
  2. Both extend from Number class and implement comparable interface

Now back to your main question in terms of performance, there is not much of difference in terms of performance between the two. If you can present your information in BigDecimal just use that so you don't have to convert it over to BigInteger but again look at the program and see if it does make sense to only use BigDecimal all the time. The main difference between the BigInteger and BigDecimal is that BigInteger supports arbitrary-precision integers and BigDecimal is for arbitrary-precision fixed-point numbers.

Here are my sources and good luck :)

NY University

Colorado University