Package com.singularsys.jep.bigdecimal.functions

# Class BigDecRound

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryFunction
com.singularsys.jep.functions.Round
com.singularsys.jep.bigdecimal.functions.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:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected RoundingMode`
  `mode`
  `protected int`
  `scale`

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BigDecRound()`
  Constructor with a rounding mode matching the behaviour of `Math.round(double)`, with ties rounded to positive infinity.
  `BigDecRound(RoundingMode mode)`
  Constructor with a specified rounding mode.
  `BigDecRound(RoundingMode mode, int scale)`
  Fixed precision setup, with a given number of decimal places.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getDecimalPlaces()`
  Gets the number of decimal places used.
  `String`
  `getDescription()`
  Return a description of the function from the properties file.
  `RoundingMode`
  `getMode()`
  `Object`
  `round(Object l)`
  `Object`
  `round(Object l, Object r)`
  `void`
  `setDecimalPlaces(int scale)`
  Sets the number of decimal places to use.
  `void`
  `setMode(RoundingMode mode)`

  ### Methods inherited from class com.singularsys.jep.functions.Round

  `checkNumberOfParameters, eval, round, run`

  ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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

  - ### round

    public Object round(Object l) throws EvaluationException
    Overrides:
      `round` in class `Round`
    Throws:
      `EvaluationException`

  - ### round

    public Object round(Object l, Object r) throws EvaluationException
    Overrides:
      `round` in class `Round`
    Throws:
      `EvaluationException`

  - ### getDescription

    public String getDescription()
    Description copied from class: `PostfixMathCommand`
    Return a description of the function from the properties file. The property name is the class name followed by ".description". The property is found using the `JepMessages` class, which can be configured to add additional properties files. If `PostfixMathCommand.setDescription(String)` has been called, return the description set by that method instead.
    Specified by:
      `getDescription` in interface `PostfixMathCommandI`
    Overrides:
      `getDescription` in class `PostfixMathCommand`
    Returns:
      the description of the function

  - ### getMode

    public RoundingMode getMode()

  - ### setMode

    public void setMode(RoundingMode mode)

  - ### getDecimalPlaces

    public int getDecimalPlaces()
    Description copied from interface: `FixedPrecisionFunctionI`
    Gets the number of decimal places used.
    Specified by:
      `getDecimalPlaces` in interface `FixedPrecisionFunctionI`
    Returns:
      either zero, a positive number or -1 for floating-point formats

  - ### setDecimalPlaces

    public void setDecimalPlaces(int scale)
    Description copied from interface: `FixedPrecisionFunctionI`
    Sets the number of decimal places to use.
    Specified by:
      `setDecimalPlaces` in interface `FixedPrecisionFunctionI`
    Parameters:
      `scale` - either zero, a positive number or -1 for floating-point formats