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
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:
-
Field Summary
FieldsFields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with a rounding mode matching the behaviour ofMath.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 TypeMethodDescriptionintGets the number of decimal places used.Return a description of the function from the properties file.getMode()voidsetDecimalPlaces(int scale) Sets the number of decimal places to use.voidsetMode(RoundingMode mode) Methods inherited from class com.singularsys.jep.functions.Round
checkNumberOfParameters, eval, round, runMethods 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
-
Field Details
-
mode
-
scale
protected int scale
-
-
Constructor Details
-
BigDecRound
public BigDecRound()Constructor with a rounding mode matching the behaviour ofMath.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 inRoundingMode. -
BigDecRound
Constructor with a specified rounding mode.- Parameters:
mode-
-
BigDecRound
Fixed precision setup, with a given number of decimal places. One parameter functionsround(x),rint(x),ceil(x), andfloor(x), are first rounded and then converted to BigDecimals with the specified number of decimal digits. Two parameter functionsround(x,k),rint(x,k)are returned withkdigits.- Parameters:
mode- either aRoundingModeornullfor rounding that matchesMath.round(double)scale- the number of decimal digits to use in the one-parameter case.
-
-
Method Details
-
round
- Overrides:
roundin classRound- Throws:
EvaluationException
-
round
- Overrides:
roundin classRound- Throws:
EvaluationException
-
getDescription
Description copied from class:PostfixMathCommandReturn a description of the function from the properties file. The property name is the class name followed by ".description". The property is found using theJepMessagesclass, which can be configured to add additional properties files. IfPostfixMathCommand.setDescription(String)has been called, return the description set by that method instead.- Specified by:
getDescriptionin interfacePostfixMathCommandI- Overrides:
getDescriptionin classPostfixMathCommand- Returns:
- the description of the function
-
getMode
-
setMode
-
getDecimalPlaces
public int getDecimalPlaces()Description copied from interface:FixedPrecisionFunctionIGets the number of decimal places used.- Specified by:
getDecimalPlacesin interfaceFixedPrecisionFunctionI- Returns:
- either zero, a positive number or -1 for floating-point formats
-
setDecimalPlaces
public void setDecimalPlaces(int scale) Description copied from interface:FixedPrecisionFunctionISets the number of decimal places to use.- Specified by:
setDecimalPlacesin interfaceFixedPrecisionFunctionI- Parameters:
scale- either zero, a positive number or -1 for floating-point formats
-