The BigDecimal(double) constructor can have unpredictable behaviors. It is preferable to use BigDecimal(String) or BigDecimal.valueOf(double).

Use with AISystem.out.println(new BigDecimal(135.69)); //135.68999999999999772626324556767940521240234375
System.out.println(new BigDecimal("135.69")); // 135.69
System.out.println(new BigDecimal("13۵.۶9")); // 135.69
System.out.println(BigDecimal.valueOf(135.69)); // 135.69

The documentation for BigDecimal(double) explains in detail:

  1. The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1) in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1), but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.
  2. The String constructor, on the other hand, is perfectly predictable: writing new BigDecimal("0.1") creates a BigDecimal which is exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the String constructor be used in preference to this one.
  3. When a double must be used as a source for a BigDecimal, note that this constructor provides an exact conversion; it does not give the same result as converting the double to a String using the Double.toString(double) method and then using the BigDecimal(String) constructor. To get that result, use the static valueOf(double) method.
Answer from Marlon Patrick on Stack Overflow
Top answer
1 of 8
185

The BigDecimal(double) constructor can have unpredictable behaviors. It is preferable to use BigDecimal(String) or BigDecimal.valueOf(double).

Use with AISystem.out.println(new BigDecimal(135.69)); //135.68999999999999772626324556767940521240234375
System.out.println(new BigDecimal("135.69")); // 135.69
System.out.println(new BigDecimal("13۵.۶9")); // 135.69
System.out.println(BigDecimal.valueOf(135.69)); // 135.69

The documentation for BigDecimal(double) explains in detail:

  1. The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1) in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1), but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.
  2. The String constructor, on the other hand, is perfectly predictable: writing new BigDecimal("0.1") creates a BigDecimal which is exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the String constructor be used in preference to this one.
  3. When a double must be used as a source for a BigDecimal, note that this constructor provides an exact conversion; it does not give the same result as converting the double to a String using the Double.toString(double) method and then using the BigDecimal(String) constructor. To get that result, use the static valueOf(double) method.
2 of 8
41
Use with AIString currency = "135.69";
System.out.println(new BigDecimal(currency));

//will print 135.69
🌐
Baeldung
baeldung.com › home › java › java string › converting string to bigdecimal in java
Converting String to BigDecimal in Java | Baeldung
June 17, 2026 - We can convert a String into BigDecimal in Java using one of the below methods: ... Let’s discuss each of them below. The easiest way to convert String to BigDecimal in Java is to use BigDecimal(String) constructor:
🌐
Java2Blog
java2blog.com › java-string-to-bigdecimal
Java String to BigDecimal – Java2Blog
You can simply use BigDecimal ‘s String based constructor to do it.
🌐
Blogger
javahungry.blogspot.com › 2020 › 01 › string-to-bigdecimal.html
2 ways to Convert String to BigDecimal in Java with Examples | Java Hungry
import java.math.*; public class JavaHungry { public static void main(String args[]) { String str = "123.45"; // Using BigDecimal(String) constructor BigDecimal num = new BigDecimal(str); // Printing BigDecimal value System.out.println("Converted String to BigDecimal : " + num); } } Output: Converted String to BigDecimal : 123.45
🌐
Java Guides
javaguides.net › 2019 › 07 › java-conversion-between-bigdecimal-and-string-tutorial.html
How to Convert String into BigDecimal in Java
June 15, 2024 - Using BigDecimal(String) Constructor: ... 54321.12 · Converting a String to a BigDecimal in Java can be accomplished using the BigDecimal constructor....
🌐
Electronics Reference
electronicsreference.com › home › java programming › how to convert a string into bigdecimal in java
How to Convert a String Into BigDecimal in Java - Electronics Reference
January 4, 2024 - No loss of precision: Unlike floating-point arithmetic, `BigDecimal` operations are not subject to rounding errors. Instances of the `BigDecimal` class are immutable, meaning the · ​numeric value cannot be changed once they are created. Operations on `BigDecimal` objects create new objects rather than modifying existing ones. The string constructor allows `BigDecimal` to be constructed using a `String` representation, which helps in avoiding inaccuracies that may arise when representing decimal numbers using floating-point literals.
🌐
Coderanch
coderanch.com › t › 385788 › java › converting-String-Bigdecimal
Problem while converting String to Bigdecimal (Java in General forum at Coderanch)
You must use a decimal point, not a comma, to separate the integer and fractional parts of the value passed to BigDecimal. Since you can�t use the new DecimalFormat support, you�ll have to replace the comma by a decimal point before converting the string to a BigDecimal.
Find elsewhere
🌐
Simplesolution
simplesolution.dev › java-convert-string-to-bigdecimal
Java Convert String to BigDecimal - Simple Solution
args) { String stringValue = "123456"; BigDecimal bigDecimal = new BigDecimal(stringValue); System.out.print(bigDecimal); } } The output as below.
🌐
Talkerscode
talkerscode.com › howto › string-to-bigdecimal-in-java.php
String To Bigdecimal In Java - TalkersCode.com
In general, we recommend using the new BigDecimal(String) method for this purpose. I hope this article on string to bigdecimal in java helps you and the steps and method mentioned above are easy to follow and implement.
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.text › to-big-decimal.html
toBigDecimal
Splits this char sequence into a list of strings each not exceeding the given size. ... Splits this char sequence into several char sequences each not exceeding the given size and applies the given transform function to an each.
🌐
GitHub
gist.github.com › f5f307fc246ca3e9226d
Convert String to BigDecimal · GitHub
Convert String to BigDecimal. GitHub Gist: instantly share code, notes, and snippets.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
July 21, 2026 - Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor and with rounding according to the context settings.
🌐
Coderanch
coderanch.com › t › 374547 › java › convert-String-BigDecimal
How to convert String to BigDecimal (Java in General forum at Coderanch)
September 10, 2004 - Hi Otrebron, To learn more about the methods of BigDecimal, refer to Java API. Joyce [ September 10, 2004: Message edited by: Joyce Lee ] ... BigDecimal(String val) Translates the string representation of a BigDecimal into a BigDecimal.
🌐
Jaspersoft Community
community.jaspersoft.com › home › forum › convert the string to big decimal with format ("##,##0.00") in jasperreport
Convert the String to Big Decimal with format ("##,##0.00") in Jasperreport - Products - Jaspersoft Community
December 5, 2023 - I would like to convert the field from String to Big Decimal with Format ("##,##0.00") in Java. Previously, we got the DataSource from sql, but for now using csv as datasource. it mean all of the fields is using string format.