com.singularsys.jep.functions

## Class Round

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

- All Implemented Interfaces:
    PostfixMathCommandI, java.io.Serializable
  Direct Known Subclasses:
    BigDecRound, RInt

      public class Round
      extends NaryFunction

  A PostfixMathCommandI which rounds a number.
  round(a) adds 0.5 to the argument and returns the closest integer.
  round(a,3) rounds the argument to 3 decimal places.

  Note: This class was changed in version 3.4. Prior to 3.4, this class used the Math.rint method. In 3.4 and future releases Math.round will be used instead. The effect is changing the rounding behaviour when the input is equally close to two integers, Math.round rounds 1.5 down and Math.rint round it up.

  Author:
    Richard Morris
  See Also:
    `RInt`, Serialized Form

- - ### Field Summary

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

      `curNumberOfParameters, name, NaN, numberOfParameters`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Round()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `checkNumberOfParameters(int n)` Must have one or more parameter
    `java.lang.Object` | `eval(java.lang.Object[] args)` Evaluate the function
    `protected double` | `round(double val)` The rounding method which implements the core rounding operation used in this class.
    `java.lang.Object` | `round(java.lang.Object param)`
    `java.lang.Object` | `round(java.lang.Object l, java.lang.Object r)`
    `void` | `run(java.util.Stack<java.lang.Object> inStack)` Creates an array of object then calls `NaryFunction.eval(Object[])`

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

      `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString`

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

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

- - ### Constructor Detail

    - #### Round

          public Round()

  - ### Method Detail

    - #### checkNumberOfParameters

          public boolean checkNumberOfParameters(int n)

      Must have one or more parameter
      Specified by:
        `checkNumberOfParameters` in interface `PostfixMathCommandI`
      Overrides:
        `checkNumberOfParameters` in class `PostfixMathCommand`
      Parameters:
        `n` - number of parameters function will be called with.
      Returns:
        false if an illegal number of parameters is supplied, true otherwise.

    - #### run

          public void run(java.util.Stack<java.lang.Object> inStack)
                   throws EvaluationException

      Description copied from class: `NaryFunction`
      Creates an array of object then calls `NaryFunction.eval(Object[])`
      Specified by:
        `run` in interface `PostfixMathCommandI`
      Overrides:
        `run` in class `NaryFunction`
      Parameters:
        `inStack` - arguments for function
      Throws:
        `EvaluationException` - if function cannot be evaluated

    - #### round

          public java.lang.Object round(java.lang.Object l,
                                        java.lang.Object r)
                                 throws EvaluationException

      Throws:
        `EvaluationException`

    - #### round

          public java.lang.Object round(java.lang.Object param)
                                 throws EvaluationException

      Throws:
        `EvaluationException`

    - #### round

          protected double round(double val)

      The rounding method which implements the core rounding operation used in this class. Other subclasses (such as RInt) can override this to perform custom rounding.
      Parameters:
        `val` - number to round
      Returns:
        the rounded value
      Since:
        3.4.0

    - #### eval

          public java.lang.Object eval(java.lang.Object[] args)
                                throws EvaluationException

      Description copied from class: `NaryFunction`
      Evaluate the function
      Specified by:
        `eval` in class `NaryFunction`
      Parameters:
        `args` - arguments to the function
      Returns:
        value returned by the function
      Throws:
        `EvaluationException` - if the calculation cannot be performed

Copyright © 2018 Singular Systems http://www.singularsys.com/jep