Package com.singularsys.jep.functions

# Class RoundBD

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryFunction
com.singularsys.jep.functions.Round
com.singularsys.jep.functions.RoundBD

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

public class RoundBD extends Round
Rounding functions using BigDecimals rounding method. See `BigDecimal.setScale(int, RoundingMode)`. This should handle tricky cases like `round(265.335,2)` correctly. 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. If the input value is a BigDecimal the result is also a BigDecimal, all other type of input Double, Integer give Double results.

Since:
  Jep 4.1
Author:
  Richard Morris
See Also:
  - Serialized Form

- ## Field Summary

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

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RoundBD()`
  Constructor with a rounding mode matching the behaviour or Math.round, that is it equivalent to Math.floor(a + 0.5d).
  `RoundBD(RoundingMode mode)`
  Constructor with a specified rounding mode.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `round(Object l)`
  `Object`
  `round(Object l, Object r)`
  `BigDecimal`
  `roundBD(BigDecimal l, int scale)`
  Round a big decimal to a set number of decimal places

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

- ## Constructor Details

  - ### RoundBD

    public RoundBD()
    Constructor with a rounding mode matching the behaviour or Math.round, that is it equivalent to Math.floor(a + 0.5d). This does not match any of the modes in `RoundingMode`.

  - ### RoundBD

    public RoundBD(RoundingMode mode)
    Constructor with a specified rounding mode.
    Parameters:
      `mode` -

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

  - ### roundBD

    public BigDecimal roundBD(BigDecimal l, int scale)
    Round a big decimal to a set number of decimal places
    Parameters:
      `l` - value to round
      `scale` - number of decimal places
    Returns:
      a BigDecimal value