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
Rounding functions using
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.2
- Author:
- Richard Morris
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
-
Constructor Summary
ConstructorDescriptionRoundBD()
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 TypeMethodDescriptionroundBD
(BigDecimal l, int scale) Round a big decimal to a set number of decimal placesMethods 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, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
-
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 inRoundingMode
. -
RoundBD
Constructor with a specified rounding mode.- Parameters:
mode
-
-
-
Method Details
-
round
- Overrides:
round
in classRound
- Throws:
EvaluationException
-
round
- Overrides:
round
in classRound
- Throws:
EvaluationException
-
roundBD
Round a big decimal to a set number of decimal places- Parameters:
l
- value to roundscale
- number of decimal places- Returns:
- a BigDecimal value
-