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

Answer from Rohan Grover on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-divide-method-in-java-with-examples
BigDecimal divide() Method in Java with Examples - GeeksforGeeks
July 12, 2025 - 800000 Reference: https://docs...java.math.BigDecimal) This method is used to calculate the quotient of two BigDecimals whose value is (this / divisor), with rounding according to the context settings....
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
October 20, 2025 - Returns a BigDecimal whose value is (this / divisor), and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied. The new divide(BigDecimal, int, RoundingMode) method should be used in preference to this ...
🌐
Tutorialspoint
tutorialspoint.com › home › java/math › bigdecimal divide with rounding modes and scale
BigDecimal Division in Java: Rounding Modes & Scale
September 1, 2008 - The java.math.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode) returns a BigDecimal whose value is (this / divisor), and whose scale is as specified. If rounding must be performed to generate a result with the specified ...
🌐
Medium
medium.com › @AlexanderObregon › javas-bigdecimal-divide-method-explained-204688fe717a
Java’s BigDecimal.divide() Method Explained | Medium
January 13, 2025 - Learn about Java's BigDecimal.divide() method for precise division, handling rounding modes, and its use in financial calculations with practical examples.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.math.bigdecimal.divide
BigDecimal.Divide Method (Java.Math) | Microsoft Learn
Returns a BigDecimal whose value is (this / divisor), and whose scale is as specified. [Android.Runtime.Register("divide", "(Ljava/math/BigDecimal;II)Ljava/math/BigDecimal;", "GetDivide_Ljava_math_BigDecimal_IIHandler")] public virtual ...
🌐
Tutorialspoint
tutorialspoint.com › java › math › bigdecimal_divide_roundingmode.htm
Java.math.BigDecimal.divide() Method
The following example shows the usage of math.BigDecimal.divide() method. package com.tutorialspoint; import java.math.*; public class BigDecimalDemo { public static void main(String[] args) { // create 3 BigDecimal objects BigDecimal bg1, bg2, bg3; bg1 = new BigDecimal("16"); bg2 = new BigDecimal("3"); // divide bg1 with bg2 // 0 specifies BigDecimal.ROUND_UP bg3 = bg1.divide(bg2, 0); String str = "Division result is " +bg3; // print bg3 value System.out.println( str ); } }
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 7 )
Returns a BigDecimal whose value is (this / divisor), and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied. The new divide(BigDecimal, int, RoundingMode) method should be used in preference to this ...
🌐
Coderanch
coderanch.com › t › 557228 › java › Divide-BigDecimal-Integer
Divide BigDecimal by Integer (Java in General forum at Coderanch)
varBigDecimal1.divide(BigDecimal.valueOf(varInteger1.doubleValue())) ... Why don't you tell us - whats happening that you think is wrong. Looks OK to me! (BigDecimal is immutable so you need to assign the result to another variable though) Cheers - Sam. Twisters - The new age Java Quiz || My Blog
Find elsewhere
🌐
Coderanch
coderanch.com › t › 552789 › java › BigDecimal-divide
BigDecimal divide() (Java in General forum at Coderanch)
So I was noticing imprecision with ... from the divide() method. Would it be possible to fix the method to make it accurate to more sig figs? Or is there an inevitable reason for the shortcoming? What made me notice it was calculating derangements (aka subfactorials). I used the asymptotic formula !n = n!/e. I have a method for factorials that returns a BigInteger. I initialized a BigDecimal from the ...
🌐
Java2Blog
java2blog.com › home › core java › bigdecimal › bigdecimal divide
BigDecimal divide - Java2Blog
January 11, 2021 - In this tutorial we will see about BigDecimal‘s divide method. BigDecimal’s divide method is used to divide one BigDecimal by another. You can specify scale and rounding mode to get the output according to your need.
🌐
RoseIndia
roseindia.net › java › java-bigdecimal › bigDecimal-divide-int.shtml
Java BigDecimal divide examples
bigdecimal_objectName = bigdecimal_objectDividendName.bigdecimal.divide(bigdecimal_objectDivisorName, int scale, int roundingMode); Java_BigDecimal_divide_int_scale_int_roundingMode.java
🌐
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 - Returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.
🌐
ZetCode
zetcode.com › java › bigdecimal
Java BigDecimal - high-precision calculations in Java with BigDecimal
BigDecimal res4 = val1.divide(BigDecimal.TEN, RoundingMode.DOWN); System.out.println(res4); When doing the division operation, we also need to specify the rounding mode. $ java Main.java 6.18 0.70 9.4256 0.34 1.255474452554745
🌐
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 - Returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.
🌐
javaspring
javaspring.net › java_math › mastering_the_java_math_bigdecimal_divide_method_a_deep_dive_into_precise_numerical_operations
Mastering the Java.math.BigDecimal.divide() Method: A Deep Dive into Precise Numerical Operations — javaspring.net
We then divide the dividend by the divisor with a scale of 2 (two digits after the decimal point) and use the ROUND_HALF_UP rounding mode. When the division operation results in a non-integer quotient, the BigDecimal class can handle the remainder ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-divideandremainder-method-in-java-with-examples
BigDecimal divideAndRemainder() Method in Java with Examples - GeeksforGeeks
July 12, 2025 - The java.math.BigDecimal.divideAndRemainder(BigDecimal divisor) is used to calculate both quotient and remainder of two BigDecimals.
🌐
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])
Returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.