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 - The java.math.BigDecimal.divide(BigDecimal divisor) is used to calculate the Quotient of two BigDecimals. The Quotient is given by (this / divisor). This method performs an operation upon the current BigDecimal by which this method is called ...
🌐
Tutorialspoint
tutorialspoint.com › java › math › bigdecimal_divide_rdroundingmode_scale.htm
Java.math.BigDecimal.divide() Method
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 - The BigDecimal.divide() method in Java is designed to handle division operations with precision, particularly useful for applications requiring exact decimal calculations.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
July 21, 2026 - In the case of divide, the exact ... 1 divided by 3. If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException is thrown. Otherwise, the exact result of the division is returned, as done for other operations. When the precision setting is not 0, the rules of BigDecimal arithmetic ...
🌐
Java2Blog
java2blog.com › home › core java › bigdecimal › bigdecimal divide
BigDecimal divide - Java2Blog
January 11, 2021 - BigDecimal's divide method is used to divide one BigDecimal with another BigDecimal.
🌐
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 ...
Find elsewhere
🌐
Reddit
reddit.com › r/learnjava › bigdecimal division
r/learnjava on Reddit: BigDecimal division
January 16, 2023 -

For the class BigDemical, the calculation "divide" continue until the decimal terminates. This does not always happen, and with my program, it almost never does. However, I cannot find a way to specify the precision I want, that being 2^x for 0<x<35 bits of precision. I have read https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html, and it seems that it is possible to have arbitrary precision, but I cannot figure out how to specific any precision. I thought it might be divide(BigDecimal divisor, MathContext mc) , but this does not appear to be accurate enough. It caps out at 128, not 2^35. Does anyone know how I can specific the precision within 2N and N/2 digits for any N? Thanks and sorry if this has an obvious answer.

Top answer
1 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 3
1
There is scale() method. Is it what you are looking for?
🌐
Android Developers
developer.android.com › api reference › bigdecimal
BigDecimal  |  API reference  |  Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
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 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.
🌐
wikiHow
wikihow.tech › computers and electronics › software › programming › java › 3 ways to divide in java with decimals - wikihow tech
3 Ways to Divide in Java with Decimals - wikiHow Tech
April 17, 2025 - If dividing two integers results ... to divide two integers and get a decimal result, you can cast either the numerator or denominator to double before the operation....
🌐
IONOS
ionos.com › digital guide › websites › web development › java class: bigdecimal
How to use Java BigDecimal to display floating point numbers
July 26, 2024 - ExampleOne = ExampleOne.multiply(ExampleTwo); System.out.println ("Here is the result: " + ExampleOne);java · If you want to divide two BigDec­i­mal objects in Java, use the divide() method.
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-class-java
BigDecimal Class in Java - GeeksforGeeks
March 8, 2024 - BigDecimal divide​(BigDecimal divisor, int scale, RoundingMode roundingMode): This method returns a BigDecimal whose value is (this / divisor), and whose scale is as specified.
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › math › BigDecimal.html
BigDecimal (Java SE 9 & JDK 9 )
In the case of divide, the exact ... 1 divided by 3. If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException is thrown. Otherwise, the exact result of the division is returned, as done for other operations. When the precision setting is not 0, the rules of BigDecimal arithmetic ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-divideandremainder-method-in-java-with-examples
BigDecimal divideAndRemainder() Method in Java with Examples - GeeksforGeeks
July 12, 2025 - ... // Java program to demonstrate ... "65245"; // Convert the string input to BigDecimal BigDecimal a = new BigDecimal(input1); BigDecimal divisor = new BigDecimal(input2); // Using divideAndRemainder() method res = ...
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 17 & JDK 17)
April 21, 2026 - In the case of divide, the exact ... 1 divided by 3. If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException is thrown. Otherwise, the exact result of the division is returned, as done for other operations. When the precision setting is not 0, the rules of BigDecimal arithmetic ...
🌐
Oracle
docs.oracle.com › en › java › javase › 18 › docs › api › java.base › java › math › BigDecimal.html
BigDecimal (Java SE 18 & JDK 18)
August 18, 2022 - In the case of divide, the exact ... 1 divided by 3. If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException is thrown. Otherwise, the exact result of the division is returned, as done for other operations. When the precision setting is not 0, the rules of BigDecimal arithmetic ...