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

System.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
🌐
Java2Blog
java2blog.com › home › conversion › java string to bigdecimal
Java convert String to BigDecimal
January 12, 2021 - You can simply use BigDecimal ‘s String based constructor to do it. Above constructor convert String representation of BigDecimal to BigDecimal Let’s see this with the help of example:
🌐
Simplesolution
simplesolution.dev › java-convert-string-to-bigdecimal
Java Convert String to BigDecimal
import java.math.BigDecimal; public class StringToBigDecimalExample1 { public static void main(String...
Discussions

Convert string to BigDecimal in java - Stack Overflow
I am reading a currency from XML into Java. ... Why is it that it outputs this many numbers? How can I avoid this? All I want is for it to output 135.69. ... Your currency is not even a String to start with; just use the BigDecimal constructor having a String as an argument. More on stackoverflow.com
🌐 stackoverflow.com
Convert the String to Big Decimal with format ("##,##0.00") in Jasperreport - Products - Jaspersoft Community
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. Note -GRP_FAC_ACT_BAL: StringSyntax: $F{GRP_FAC_ACT_BAL}==null?"":new ... More on community.jaspersoft.com
🌐 community.jaspersoft.com
December 5, 2023
How to Convert String in to BigDecimal
Hi to all, I need to convert a file let us say .txt file or .html file in to BigDecimal. To do this first I will read the file and stored in Byte Array and then converted byte array in to String. The... More on forums.oracle.com
🌐 forums.oracle.com
November 20, 2007
Localized String to BigDecimal
I would like to build something now that I never need to touch again! Plus, I want to safe myself the work of trying to find out what each locale's settings are :) Java is riddled with all these localization options, yet I cannot safely convert to BigDecimal from String? More on experts-exchange.com
🌐 experts-exchange.com
November 14, 2009
🌐
Baeldung
baeldung.com › home › java › java string › converting string to bigdecimal in java
Converting String to BigDecimal in Java | Baeldung
January 14, 2026 - Using NumberFormat.getCurrencyInstance(Locale.FRANCE) applies these formatting rules automatically, allowing the parser to interpret “348,45 €” correctly and produce the expected BigDecimal value of 348.45. By relying on locale-specific NumberFormat instances, we can accurately handle currency strings from different regions, ensuring reliable numeric conversion in internationalized applications. In this article, we learned that Java provides us with multiple methods to convert String to BigDecimal values.
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).

System.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
String currency = "135.69";
System.out.println(new BigDecimal(currency));

//will print 135.69
🌐
Blogger
javahungry.blogspot.com › 2020 › 01 › string-to-bigdecimal.html
2 ways to Convert String to BigDecimal in Java with Examples | Java Hungry
The first step is to convert the String to Double. The second step is to convert Double to BigDecimal, using BigDecimal.valueOf(double) method. As shown in the example below: import java.math.*; public class JavaHungry { public static void main(String args[]) { String str = "123.45"; // Converting ...
🌐
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 - Converting a String to a BigDecimal in Java can be accomplished using the BigDecimal constructor. It is essential to handle the NumberFormatException to ensure your code is robust and can handle invalid input gracefully.
🌐
Jaspersoft Community
community.jaspersoft.com › forum
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.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 614782 › java › Convert-string-BigDecimal
Convert string to BigDecimal (Java in General forum at Coderanch)
Hi, while parsing the data from web, I am getting the string as "5�952" and checking wherther it is numeric value or not using str.matches("-?\\d+(\\.\\d+)?") . If it returns true then I am converting this to BigDecimal. While converting i am getting NumberFormalException.
🌐
Coderanch
coderanch.com › t › 385788 › java › converting-String-Bigdecimal
Problem while converting String to Bigdecimal (Java in General forum at Coderanch)
Campbell was referring to the precise description in the BigDecimal constructor JavaDoc. 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.
🌐
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.
🌐
Qlik Community
community.qlik.com › t5 › Talend-Studio › Convert-a-string-to-Big-Decimal › td-p › 2348714
Solved: Convert a string to Big Decimal - Qlik Community - 2348714
November 15, 2024 - The resulting string "6.00" can then be converted to a `BigDecimal` object using its constructor. Note that you may also need to handle any potential exceptions that can be thrown by the `BigDecimal` constructor, such as `NumberFormatException` if the input string is not a valid decimal number. SkyWard Alpine Login ... Ditto - same here! ... You can use the `BigDecimal` class in Java to convert the string "$6.00" to a `BigDecimal` object.
🌐
Oracle
forums.oracle.com › ords › apexds › post › how-to-convert-string-in-to-bigdecimal-9326
How to Convert String in to BigDecimal
November 20, 2007 - Hi to all, I need to convert a file let us say .txt file or .html file in to BigDecimal. To do this first I will read the file and stored in Byte Array and then converted byte array in to String. The...
🌐
Experts Exchange
experts-exchange.com › questions › 24899969 › Localized-String-to-BigDecimal.html
Solved: Localized String to BigDecimal | Experts Exchange
November 14, 2009 - You can use NumberFormat and use http://java.sun.com/javase/6/docs/api/java/text/NumberFormat.html#getNumberInstance(java.util.Locale) to find out format to use for the locale. ... Sorry for the misconception, but I need to go the other way! So I'll give to example values: String nl_NL_BigDecimal = "343.298.723.948.729.384.0
🌐
IBM
community.ibm.com › community › user › discussion › coverting-string-to-bigdecimal-1
Coverting String to BigDecimal | IBM webMethods Hybrid Integration
February 21, 2014 - Can a String be converted to BigDecimal(java.math.BigDecimal) type?I have an input value as a string which is actually a number. I need to pass it to a JDBC ada
🌐
Qlik Community
community.qlik.com › t5 › Talend-Studio › Error-converting-string-to-bigdecimal-on-tMap › td-p › 2298377
Solved: Error converting string to bigdecimal on tMap - Qlik Community - 2298377
March 6, 2018 - This checks for null and if it is not null, removes all bad characters and converts to a BigDecimal. If it is null, it returns null. ... Ditto - same here! ... This question may have been overlooked as it probably is better suited to the "Design and Development" section. It looks like your issues are caused by your number (I assume it is returned as a String from the file) being in a format that could not be converted.
🌐
Stack Overflow
stackoverflow.com › questions › 77443264 › convert-the-string-to-big-decimal-with-format-0-00
Convert the String to Big Decimal with format ("##,##0.00") ...
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 al...
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 17 & JDK 17)
January 20, 2026 - Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified and with rounding according to the context settings. ... If the sequence of characters is already available within a character array, using this constructor is faster than converting the char array to string and using the BigDecimal(String) constructor.
🌐
Codementor
codementor.io › community › bigdecimal class in java
BigDecimal Class in Java | Codementor
June 23, 2024 - According to its Javadoc, a BigDecimal represents an immutable, arbitrary-precision decimal number. A BigDecimal consists of an arbitrary-precision integer unscaled value and a 32-bit integer scale. There are two main ways of creating a BigDecimal: using constructors and using static methods BigDecimal#valueOf(). BigDecimal offers multiple constructors with different parameter types: BigInteger, long, double, char, String...
🌐
Grails
gorm.grails.org › latest › rx › api › org › grails › datastore › mapping › model › types › conversion › StringToBigDecimalConverter.html
Redirecting...
This page has moved to https://grails.apache.org/docs-legacy-gorm/latest/rx/api/org/grails/datastore/mapping/model/types/conversion/StringToBigDecimalConverter.html