Package com.reve.utils
Class DoubleFormatter
java.lang.Object
com.reve.utils.DoubleFormatter
This class is aimed to round e double value to a given decimal places. For memory leakage issue, we cannot use
Double.parseDouble(String) method. Instead, we will divide and round.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDoubleFormatter(int decimalPlace) ConstructorDoubleFormatter(int decimalPlace, DoubleFormatter.RoundingMethod roundingMethod) Constructor -
Method Summary
Modifier and TypeMethodDescriptionformatDouble(Double value) Round the double value to the decimal value given in the constructor.
-
Constructor Details
-
DoubleFormatter
Constructor- Parameters:
decimalPlace- Number of digits after dot, the value should be rounded to.roundingMethod- Rounding method can be either -DoubleFormatter.RoundingMethod.HALF_UPwhere immediate next digit of last considered digit greater equal 5 will be considered to ceiling. and less than 5 will be considered to be floor. or -DoubleFormatter.RoundingMethod.CEILINGwhere greater than 0 will be considered to ceiling. or -DoubleFormatter.RoundingMethod.FLOORwhere all value will be considered to floor.
-
DoubleFormatter
public DoubleFormatter(int decimalPlace) Constructor- Parameters:
decimalPlace- Number of digits after dot, the value should be rounded to.
-
-
Method Details
-
formatDouble
Round the double value to the decimal value given in the constructor.- Parameters:
value- The value to be rounded.- Returns:
- Rounded value.
-