Class Round

All Implemented Interfaces:
PostfixMathCommandI, Serializable
Direct Known Subclasses:
BigDecRound, RInt, RoundBD

public class Round extends NaryFunction
A PostfixMathCommandI which rounds a number. The single argument version, round(a), uses Math.round(double) to round to the closest integer. The two argument version 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.

In Jep 4.1 fixes a bug with round(100000,-5) -> 99999.99999999999. An alternative algorithm is provided by the RoundBD class, this uses BigDecimal's setscale(scale,mode) method. This can improve results for cases like round(265.335,2) where the floating-point representation of 265.335 is not exact.

Author:
Richard Morris
See Also: