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 ...
Discussions

java - Division of BigDecimals - Stack Overflow
I want to use BigDecimal in some calculations. Imagine that in some intermediate step there is the following division new BigDecimal(1).divide(new BigDecimal(4)). I understand that in this case the... More on stackoverflow.com
🌐 stackoverflow.com
java - division of bigdecimal by integer - Stack Overflow
I want to divide a bigdecimal value with an integer.i have rounded the bigdecimal value(if it is 133.333 then rounded value is 133).given below is my code snippet. More on stackoverflow.com
🌐 stackoverflow.com
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
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
January 16, 2023
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › math › bigdecimal_divide_rdroundingmode_scale.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 with 3 scale bg3 = bg1.divide(bg2, 3, RoundingMode.CEILING); String str = "Division result is " +bg3; // print bg3 value System.out.println( str ); } }
🌐
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
🌐
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]); } }
🌐
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.
🌐
Star-school
star-school.jp › home › java programming basics masterclass › java bigdecimal divide() method explained with examples
Java BigDecimal divide Method Complete Guide for Beginners: Accurate Decimal Division | Star School
July 13, 2026 - The expression total.divide(people) means that the value stored in total is divided by the value stored in people. In this example, Java calculates 100 divided by 4 and returns a new BigDecimal representing 25.
🌐
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 - 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.
🌐
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 · 中文 – 简体
🌐
CodeGym
codegym.cc › java blog › java numbers › bigdecimal in java
BigDecimal in Java
January 15, 2025 - Use divide() with a rounding mode! import java.math.RoundingMode; BigDecimal num1 = new BigDecimal("10"); BigDecimal num2 = new BigDecimal("3"); BigDecimal result = num1.divide(num2, 2, RoundingMode.HALF_UP); System.out.println("Division Result: ...
🌐
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 - This wikiHow article will show you three ways to do decimal numbers in Java. If you want to divide two integers (non-decimal) and get a non-rounded answer, cast one of the operands to a double.
🌐
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?
🌐
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 ...
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 ·
🌐
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.