Class BigDecRound

All Implemented Interfaces:
FixedPrecisionFunctionI, PostfixMathCommandI, Serializable

public class BigDecRound extends Round implements FixedPrecisionFunctionI
Rounding functions for BigDecimals. Support all the modes in RoundingMode as well as a mode compatible with Math.round(double). Two types of function are supported round(x) rounds to 0 decimal places and round(x,k) rounds to k decimal places. This class is used to implement floor(x) and ceil(x) functions as well as rint(x), rint(x,k) that round to the nearest neighbour with ties rounded to the nearest even value.

A fixed point version Uses the BigDecimal.setScale(int,RoundingMode) method.

Since:
Jep 3.5
Author:
Richard Morris
See Also:
  • Field Details

    • mode

      protected RoundingMode mode
    • scale

      protected int scale
  • Constructor Details

    • BigDecRound

      public BigDecRound()
      Constructor with a rounding mode matching the behaviour of Math.round(double), with ties rounded to positive infinity. that is it equivalent to Math.floor(a + 0.5d). This does not match any of the modes in RoundingMode.
    • BigDecRound

      public BigDecRound(RoundingMode mode)
      Constructor with a specified rounding mode.
      Parameters:
      mode -
    • BigDecRound

      public BigDecRound(RoundingMode mode, int scale)
      Fixed precision setup, with a given number of decimal places. One parameter functions round(x), rint(x), ceil(x), and floor(x), are first rounded and then converted to BigDecimals with the specified number of decimal digits. Two parameter functions round(x,k), rint(x,k) are returned with k digits.
      Parameters:
      mode - either a RoundingMode or null for rounding that matches Math.round(double)
      scale - the number of decimal digits to use in the one-parameter case.
  • Method Details