Setscale (int newscale,roundingmode Roundingmode)
BigDecimal The non-scaling value of the BigDecimal is determined by multiplying or dividing the appropriate power of 10 to maintain its value.
If the operation reduces the scale, the non-scale value must be removed (not multiplied), and the value can be changed, in which case the specified rounding mode is applied to the division.
Parameters:
-
-The scale of the
-
newScale BigDecimal value to return.
-
-
roundingMode -The rounding mode to apply.
-
-
Return:
-
-
a BigDecimalwhose scale is the specified value, and its non-scale value can be determined by multiplying the non-scale value of this BigDecimal by or dividing by the appropriate power of 10 to maintain its total value.
-
-
-
Keep One decimal: (
round_half_up rounding mode)
-
-
Double perCent = Obj.getnum () * 100.0/new= B.setscale (1, bigdecimal.round_half_up). Doublevalue ();
Other modes:
Round_down
-
rounding mode of close to 0. The number is never incremented (that is, truncated) until a portion is discarded. Note that this rounding mode always does not increase the size of the computed value.
Round_ceiling
-
rounding mode that is close to positive infinity. If BigDecimal is positive, the rounding behavior is the same as round_up , and if negative, the rounding behavior is the same as Round_down . Note that this rounding mode always does not reduce the calculated value.
Round_floor
-
rounding mode that is close to negative infinity. If BigDecimal is positive, the rounding behavior is the same as Round_down , and if negative, the rounding behavior is the same as round_up . Note that this rounding mode always does not increase the calculated value.
Round_half_up
Rounds the nearest number to the rounding mode that is
-
rounded up if the distance to the two adjacent numbers is equal. If part >= 0.5 is discarded, the rounding behavior is the same as round_up , otherwise the rounding behavior is the same as Round_down . Note that this is the rounding pattern that most of us have learned in primary school.
Round_half_down
Rounds the nearest number to the rounding mode that is
-
rounded up if the distance to the two adjacent numbers is equal. If part > 0.5 is discarded, the rounding behavior is the same as round_up , otherwise the rounding behavior is the same as Round_down .
Round_half_even
Rounds to the nearest
-
number, rounded to the adjacent even if the distance to the two adjacent numbers is equal. If the left part of the discard number is odd, the rounding behavior is the same as round_half_up , and if it is even, the rounding behavior is the same as Round_half_down . Note that this rounding mode minimizes cumulative errors when a series of calculations are repeated.
Round_unnecessary
-
asserts that the requested operation has precise results and therefore does not require rounding. If this rounding mode is specified for operations that obtain precise results, the arithmeticexceptionis thrown.
java-reserved x decimal places