Using the proper locale allows one to avoid changing decimal symbols:

DecimalFormat nf = (DecimalFormat) NumberFormat.getInstance(Locale.GERMANY);
nf.setParseBigDecimal(true);
BigDecimal bd = (BigDecimal) nf.parse("2,6");

And this ensures the scale of 2 is applied:

bd = bd.setScale(2, RoundingMode.HALF_UP); //2.60

If formatting the number as string in the same locale is required, the following should work (and perhaps preferred to bd.toString()):

NumberFormat nf2 = NumberFormat.getNumberInstance(Locale.GERMANY);
nf2.setMinimumFractionDigits(2);
//outputs "2,60"
Answer from ernest_k on Stack Overflow
🌐
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 - bigDecimalValue.setScale(2, RoundingMode.HALF_UP) sets the scale to 2 decimal places and uses the HALF_UP rounding mode.
🌐
Baeldung
baeldung.com › home › java › java string › converting string to bigdecimal in java
Converting String to BigDecimal in Java | Baeldung
May 19, 2021 - The DecimalFormat.parse method returns a Number, which we convert to a BigDecimal number using the setParseBigDecimal(true).
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
🌐
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.
🌐
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.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
October 20, 2025 - A standard canonical string form of the BigDecimal is created as though by the following steps: first, the absolute value of the unscaled value of the BigDecimal is converted to a string in base ten using the characters '0' through '9' with no leading zeros (except if its value is zero, in which case a single '0' character is used). Next, an adjusted exponent is calculated; this is the negated scale, plus the number of characters in the converted unscaled value, less one. That is, -scale+(ulength-1), where ulength is the length of the absolute value of the unscaled value in decimal digits (its precision).
🌐
Blogger
javahungry.blogspot.com › 2020 › 01 › string-to-bigdecimal.html
2 ways to Convert String to BigDecimal in Java with Examples | Java Hungry
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 String to Double Double obj = new Double(str); ...
🌐
Qlik Community
community.qlik.com › t5 › Design-and-Development › Can-t-convert-from-String-to-BigDecimal › td-p › 2335251
Solved: Can't convert from String to BigDecimal - Qlik Community ...
April 1, 2021 - Hello, I have my input schema as BigDecimal and output Schema as BigDecimal. I must have 2 decimal places in my output. My code is giving me an error since it cannot convert from BigDecimal to String: String.valueOf(row1.Account_currency == BigDecimal.valueOf(8888888888888.00)) or should it be some...
🌐
Javaprogramto
javaprogramto.com › 2021 › 11 › java-double-2-decimal-places.html
Java Format Double - Double With 2 Decimal Points Examples JavaProgramTo.com
Look at the below example to get the more details about the BigDecimal for decimal places. package com.javaprogramto.programs.strings.todouble.decimal; import java.math.BigDecimal; public class StringToDoubleDecimalsPlaces3 { public static void main(String[] args) { String decimalValueInString = "9.144678376262"; // convert string to double double doubleDecimalValue = Double.parseDouble(decimalValueInString); System.out.println("Double in string : "+decimalValueInString); System.out.println("Double value : "+doubleDecimalValue); // BigDecimal BigDecimal bigDecimal = new BigDecimal(doubleDecimalValue); bigDecimal.setScale(2); System.out.println(""+bigDecimal.doubleValue()); } }
🌐
BeginnersBook -
beginnersbook.com › home › java › how to round a number to two decimal places in java
How to round a number to two decimal places in Java
May 31, 2024 - In this approach, there are two ...atValue)); First step is to convert the given double and float values to BigDecimal. This can be done using Double.toString() method. ... bdDouble = bdDouble.setScale(2, RoundingMode.HALF_UP); bdFloat = bdFloat.setScale(2, RoundingMode.H...
🌐
Mkyong
mkyong.com › home › java › java – display double in 2 decimal places
Java - Display double in 2 decimal places - Mkyong.com
October 29, 2021 - package com.mkyong.math.rounding; public class StringFormatExample { public static void main(String[] args) { double input = 3.14159265359; System.out.println("double : " + input); System.out.println("double : " + String.format("%.2f", input)); System.out.format("double : %.2f", input); } } ... package com.mkyong.math.rounding; import java.math.BigDecimal; import java.math.RoundingMode; public class BigDecimalExample { public static void main(String[] args) { double input = 3.14159265359; System.out.println("double : " + input); BigDecimal bd = new BigDecimal(input).setScale(2, RoundingMode.HALF_UP); double newInput = bd.doubleValue(); System.out.println("double : " + newInput); } }
🌐
Baeldung
baeldung.com › home › java › java numbers › truncate a double to two decimal places in java
Truncate a Double to Two Decimal Places in Java | Baeldung
September 24, 2025 - We can create a BigInteger by passing our double value into the constructor and directly telling it to keep two decimal places by rounding down at the same time: @Test void givenADouble_whenUsingBigDecimal_truncateToTwoDecimalPlaces(){ BigDecimal ...
🌐
Mkyong
mkyong.com › home › java › java – how to round double / float value to 2 decimal places
Java – How to round double / float value to 2 decimal places - Mkyong.com
February 25, 2025 - package com.mkyong.math.rounding; import java.math.BigDecimal; import java.math.RoundingMode; public class BigDecimalExample { public static void main(String[] args) { double input = 1205.6358; System.out.println("Original double value : " + input); // Convert double to BigDecimal BigDecimal salary = new BigDecimal(input); System.out.println("BigDecimal value : " + salary); // Round to 2 decimal places using RoundingMode.HALF_UP BigDecimal salaryRounded = salary.setScale(2, RoundingMode.HALF_UP); System.out.println("Rounded BigDecimal value : " + salaryRounded); // One-line conversion and roun
🌐
How to do in Java
howtodoinjava.com › home › java basics › round off a float number to 2 decimals in java
Round Off a Float Number to 2 Decimals in Java
February 16, 2024 - Note that we can use the given ... = Math.round(number * 100.0) / 100.0; // 4.57 // 2. Using BigDecimal BigDecimal rounded = new BigDecimal(number).setScale(2, RoundingMode.HALF_UP); // 4.57 // 3....