Medium
medium.com › @skywalkerhunter › fix-divide-java-math-bigdecimal-int-in-java-math-bigdecimal-has-been-deprecated-and-why-22fe83b07e9
Fix — divide(java.math.BigDecimal,int) in java.math.BigDecimal has been deprecated — And WHY | by Oli H. | Medium
July 18, 2020 - divide(total, BigDecimal.ROUND_HALF_UP) Press enter or click to view image in full size · A real example. Step #4 — How about the setScale? Warning:(47, 146) java: setScale(int,int) in java.math.BigDecimal has been deprecated · Same trick, search for: BigDecimal.ROUND_HALF_UP ·
Java
download.java.net › java › early_access › panama › docs › api › java.base › java › math › class-use › BigDecimal.html
Uses of Class java.math.BigDecimal (Java SE 19 & JDK 19 [build 1])
Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
Stack Overflow
stackoverflow.com › questions › 55596561 › class-com-mes-mvc-mes-apilogrecord-uses-deprecated-method-java-math-bigdecimal
class com/mes/mvc/mes/ApiLogRecord uses deprecated method java/math/BigDecimal::divide(Ljava/math/BigDecimal;I)Ljava/math/BigDecimal; - Stack Overflow
class com/mes/mvc/mes/ApiLogRecord uses deprecated method java/math/BigDecimal::divide(Ljava/math/BigDecimal;I)Ljava/math/BigDecimal;
Oracle
docs.oracle.com › en › java › javase › 23 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 23 & JDK 23)
October 17, 2024 - Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
Oracle
docs.oracle.com › javase › 9 › docs › api › java › math › BigDecimal.html
BigDecimal (Java SE 9 & JDK 9 )
... ArithmeticException - if divisor is zero, roundingMode==RoundingMode.UNNECESSARY and the specified scale is insufficient to represent the result of the division exactly. ... Deprecated. The method divide(BigDecimal, RoundingMode) should be used in preference to this legacy method.
OpenJDK
bugs.openjdk.org › browse › CCC-4943627
Deprecate rounding mode integer constants in BigDecimal ...
diff -r 92280897299f src/java.base/share/classes/java/math/BigDecimal.java --- a/src/java.base/share/classes/java/math/BigDecimal.java Mon Apr 18 14:10:14 2016 -0700 +++ b/src/java.base/share/classes/java/math/BigDecimal.java Mon Apr 18 18:41:03 2016 -0700 @@ -1536,7 +1536,7 @@ * be performed to generate a result with the specified scale, the * specified rounding mode is applied. * - * <p>The new {@link #divide(BigDecimal, int, RoundingMode)} method + * @deprecated The method {@link #divide(BigDecimal, int, RoundingMode)} * should be used in preference to this legacy method.
Coderanch
coderanch.com › t › 785638 › java › Replacing-BigDecimal-Code-Deprecated
Replacing some BigDecimal Code since Deprecated (Java in General forum at Coderanch)
Note that when a method or class is deprecated, a good first place to look for more information is in the JavaDoc for the deprecated code. In this case, that's here: BigDecimal.setScale(int,int) containing the following advice:
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 11 & JDK 11 )
January 20, 2026 - Returns a BigDecimal whose value ... is inexact but the rounding mode is UNNECESSARY. ... Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method....
Oracle
docs.oracle.com › javase › 10 › docs › api › java › math › BigDecimal.html
BigDecimal (Java SE 10 & JDK 10 )
Returns a BigDecimal whose value ... is inexact but the rounding mode is UNNECESSARY. ... Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method....
Openbravo
issues.openbravo.com › view.php
0037966: JDK 9: fix new BigDecimal related deprecation warnigns - Openbravo Issue Tracking System
JDK9 deprecated some constants in BigDecimal class related to rounding which are commonly used with the setScale & divide functions.However a simple replacement of the old constants with the new ...
Top answer 1 of 2
108
You haven't specified a scale for the result. Please try this
2019 Edit: Updated answer for JDK 13. Cause hopefully you've migrated off of JDK 1.5 by now.
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Main {
public static void main(String[] args) {
BigDecimal a = new BigDecimal("1");
BigDecimal b = new BigDecimal("3");
BigDecimal c = a.divide(b, 2, RoundingMode.HALF_UP);
System.out.println(a + "/" + b + " = " + c);
}
}
Please read JDK 13 documentation.
Old answer for JDK 1.5 :
import java.math.*;
public class x
{
public static void main(String[] args)
{
BigDecimal a = new BigDecimal("1");
BigDecimal b = new BigDecimal("3");
BigDecimal c = a.divide(b,2, BigDecimal.ROUND_HALF_UP);
System.out.println(a+"/"+b+" = "+c);
}
}
this will give the result as 0.33. Please read the API
2 of 2
-1
import java.math.*;
class Main{
public static void main(String[] args) {
// create 3 BigDecimal objects
BigDecimal bg1, bg2, bg3;
MathContext mc=new MathContext(10,RoundingMode.DOWN);
bg1 = new BigDecimal("2.4",mc);
bg2 = new BigDecimal("32301",mc);
bg3 = bg1.divide(bg2,mc); // divide bg1 with bg2
String str = "Division result is " +bg3;
// print bg3 value
System.out.println( str );
}
}
giving wrong answer
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 22 & JDK 22)
July 16, 2024 - Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
Oracle
docs.oracle.com › en › java › javase › 24 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 24 & JDK 24)
July 15, 2025 - Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
Java
download.java.net › java › early_access › valhalla › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 23 & JDK 23 [build 1])
Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 21 & JDK 21)
January 20, 2026 - Returns a BigDecimal whose value is (this × multiplicand), with rounding according to the context settings. ... Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
Apache JIRA
issues.apache.org › jira › browse › NUMBERS-83
[NUMBERS-83] Replace usage of methods deprecated in Java 9 - ASF Jira
commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java:[585,41] divide(java.math.BigDecimal,int,int) in java.math.BigDecimal has been deprecated · commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/PlaneAngle.java:[116,45] Double(double) ...
Tabnine
tabnine.com › home page › code › java › com.ibm.icu.math.bigdecimal
com.ibm.icu.math.BigDecimal.divide java code examples | Tabnine
*/ @Deprecated public static BigDecimal toBigDecimalTrunc(BigDecimal universalTime, int timeScale) { TimeScaleData data = getTimeScaleData(timeScale); BigDecimal units = new BigDecimal(data.units); BigDecimal epochOffset = new BigDecimal(data.epochOffset); return universalTime.divide(units, BigDecimal.ROUND_DOWN).subtract(epochOffset); } }
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 - Returns a BigDecimal whose value is (this × multiplicand), with rounding according to the context settings. ... Deprecated. The method divide(BigDecimal, int, RoundingMode) should be used in preference to this legacy method.
GitHub
github.com › openjdk › jdk16 › blob › master › src › java.base › share › classes › java › math › BigDecimal.java
jdk16/src/java.base/share/classes/java/math/BigDecimal.java at master · openjdk/jdk16
@Deprecated(since="9") public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode) { if (roundingMode < ROUND_UP || roundingMode > ROUND_UNNECESSARY) throw new IllegalArgumentException("Invalid rounding mode"); if (this.intCompact != INFLATED) { if ((divisor.intCompact != INFLATED)) { return divide(this.intCompact, this.scale, divisor.intCompact, divisor.scale, scale, roundingMode); } else { return divide(this.intCompact, this.scale, divisor.intVal, divisor.scale, scale, roundingMode);
Author openjdk