In this example, Java bigdecimal
class divide(BigDecimal divisor, int scale, int roundingMode) method working
is demonstrated. Example contains scale feature which is an integer type value that defines number of digits after decimal. Here the scale of the quotient will be specified in the program.
Also in the example, bigdecimal class ROUND_FLOOR
field is used that defines the Rounding mode to round towards negative infinity. Method throws Arithmetic Exception in following cases when the specified Rounding mode is
when the divisor value is zero and when the specified rounding mode does not represent a valid rounding mode.
With divisor value zero, the rounding mode becomes equal to ROUND_UNNECESSARY therefore method throws Arithmetic Exception , when the divisor value is zero.
Method also throws IllegalArgumentException in the case when the specified rounding mode is not a valid rounding mode.
Syntax for using the method:
public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode)
bigdecimal_objectDividendName.bigdecimal.divide(bigdecimal_objectDivisorName, int scale, int roundingMode);
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.