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 ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › math › BigDecimal.html
BigDecimal (Java Platform SE 8 )
October 20, 2025 - 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 ...
Discussions

BigDecimal division
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. More on reddit.com
🌐 r/learnjava
5
1
December 9, 2022
Bigdecimal division problem
If negative, the unscaled value ... The value of the number represented by the BigDecimal is therefore (unscaledValue × 10-scale). So i think that there is no need to set the scale explicitly for positive numbers and the dividend in my code is also positive.... More on thecodingforums.com
🌐 thecodingforums.com
5
January 16, 2006
Dividing BigDecimal field by String field - Products - Jaspersoft Community
Hi Everyone,I'm a newbie and attempting to divide a BigDecimal field (bdfield) by a String field (strfield) in Jaspersoft Studio.I've tried about 2 dozen approaches based on what I've read on these and other forums, but haven't been successful. Does anyone have a preferred approach?Edit: Here are... More on community.jaspersoft.com
🌐 community.jaspersoft.com
August 31, 2021
java - BigDecimal divide method either returns 0 or ArithmeticException? - Stack Overflow
When I try dividing BigDecimals using the method: divide(divisor, RoundingMode.HALF_UP) it returns 0 But if I do it without a rounding mode like this: divide(divisor) I get an ArithmeticExcepti... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
Reddit
reddit.com › r/learnjava › bigdecimal division
r/learnjava on Reddit: BigDecimal division
December 9, 2022 -

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?
🌐
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 ...
🌐
Coderanch
coderanch.com › t › 557228 › java › Divide-BigDecimal-Integer
Divide BigDecimal by Integer (Java in General forum at Coderanch)
October 29, 2011 - Ravi Kanth D wrote:I have a BigDecimal variable that I need to divide by Integer variable, below is my code, please let me know what is wrong. varBigDecimal1.divide(BigDecimal.valueOf(varInteger1.doubleValue())) There's nothing intrinsically wrong with it, but the redundant double conversion will slow things down.
Find elsewhere
🌐
The Coding Forums
thecodingforums.com › archive › archive › java
Bigdecimal division problem | Java | Coding Forums
January 16, 2006 - In your case this is -6. Set the scale to 1 to get what you want: BigDecimal quotient = BigDecimal.valueOf(10000000.0).setScale(1).divide(new BigDecimal(3),RoundingMode.CEILING); Bart
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › math › bigdecimal_divide_rdroundingmode.htm
Java.math.BigDecimal.divide() Method
The following example shows the usage of math.BigDecimal.divide() method. package com.tutorialspoint; import java.math.*; import java.lang.*; 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 rounding up bg3 = bg1.divide(bg2, RoundingMode.UP); String str = "Division result is " +bg3; // print bg3 value System.out.println( str ); } }
🌐
Coderanch
coderanch.com › t › 552789 › java › BigDecimal-divide
BigDecimal divide() (Java in General forum at Coderanch)
September 15, 2011 - So I was noticing imprecision with division of large numbers, and have concluded by process of elimination that it stems 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 BigInteger, then divided it by Math.E.
🌐
Jaspersoft Community
community.jaspersoft.com › forum
Dividing BigDecimal field by String field - Products - Jaspersoft Community
August 31, 2021 - Hi Everyone,I'm a newbie and attempting to divide a BigDecimal field (bdfield) by a String field (strfield) in Jaspersoft Studio.I've tried about 2 dozen approaches based on what I've read on these and other forums, but haven't been successful. Does anyone have a preferred approach?Edit: Here are...
🌐
GeeksforGeeks
geeksforgeeks.org › java › bigdecimal-divideandremainder-method-in-java-with-examples
BigDecimal divideAndRemainder() Method in Java with Examples - GeeksforGeeks
July 12, 2025 - Below programs is used to illustrate the divideAndRemainder() method of BigDecimal. ... // Java program to demonstrate // divideAndRemainder() method of BigDecimal import java.math.*; public class GFG { public static void main(String[] args) { // BigDecimal object to store the result BigDecimal res[]; // For user input // Use Scanner or BufferedReader // Two objects of String created // Holds the values String input1 = "456865265569"; String input2 = "65245"; // Convert the string input to BigDecimal BigDecimal a = new BigDecimal(input1); BigDecimal divisor = new BigDecimal(input2); // Using divideAndRemainder() method res = a.divideAndRemainder(divisor); // Display the result in BigDecimal System.out.println("Quotient = " + res[0] + "\nRemainder = " + res[1]); } }
🌐
Coderanch
coderanch.com › t › 443344 › java › BigDecimal-divide
BigDecimal divide question (Beginning Java forum at Coderanch)
April 29, 2009 - Hello All, Was getting the error - "java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result" while trying to do a divide of a BigDecimal by a BigDecimal. Found some code that I used to solve this problem above. The code I have does not look pretty.
🌐
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 - Returns a BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value.
🌐
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.
🌐
GitHub
github.com › tc39 › proposal-decimal › issues › 13
BigDecimal with division and other operations which need to round · Issue #13 · tc39/proposal-decimal
November 13, 2019 - Java-like: Require that the user provide the precision and/or rounding mode as a parameter when performing division · Ruby-like: Just choose an arbitrary amount of extra decimal places to use for the division result · The implicit third option is to avoid division, and instead have a div/mod operation, or a "partition" operation (to split a BigDecimal into an integer number of buckets as equally as possible, at the precision of the BigDecimal)
Published   Nov 13, 2019