Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Javadoc for the first situation:</p> <blockquote> <p>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.</p> </blockquote> <p>and the Javadoc for the second situation:</p> <blockquote> <p>Returns a BigDecimal whose value is (this / divisor), with rounding according to the context settings.</p> </blockquote> <p>referring to the javadoc for MathContext we get:</p> <blockquote> <p>Immutable objects which encapsulate the context settings which describe certain rules for numerical operators, such as those implemented by the BigDecimal class. The base-independent settings are: precision: the number of digits to be used for an operation; results are rounded to this precision roundingMode: a RoundingMode object which specifies the algorithm to be used for rounding.</p> </blockquote> <p>So in the first case, you specified a SCALE of 2, meaning that you round to 2 decimal places of accuracy, where the rounding is performed as a floor function. The second calculation has a specified PRECISION of 2, which is rounded to two digits of accuracy, where the rounding is a floor function. So, in the first case, you asked for 2 digits <em>after the decimal place</em>, and in the second, you just asked for 2 digits. If, for example, you had asked for 4 digits in your MathContext, you'd get 66.66 as you answer.</p> <p>So I don't think that this is a bug so much as that the two methods don't perform the same calculation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload