Package org.dawb.common.util.number
Class DoubleUtils
java.lang.Object
org.dawb.common.util.number.DoubleUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanequalsWithinTolerance(Number foo, Number bar, Number tolerance) Test if two numbers are equal.static booleanequalsWithinTolerances(Number foo, Number bar, Number tolerance, Number percentage) Test if two numbers are equal within an absolute or relative tolerance whichever is larger.static StringformatDouble(double value, int precision) Returns a formatted Double value given a specific DecimalFormat
If more than 4 integer, then we display the value in scientific notationstatic voidstatic doubleroundDouble(double value, int precision) Method that rounds a value to the n precision decimals
-
Constructor Details
-
DoubleUtils
public DoubleUtils()
-
-
Method Details
-
equalsWithinTolerance
Test if two numbers are equal.- Parameters:
foo-bar-tolerance-- Returns:
- true if foo equals bar within tolerance
-
equalsWithinTolerances
public static boolean equalsWithinTolerances(Number foo, Number bar, Number tolerance, Number percentage) Test if two numbers are equal within an absolute or relative tolerance whichever is larger. The relative tolerance is given by a percentage and calculated from the absolute maximum of the input numbers.- Parameters:
foo-bar-tolerance-percentage-- Returns:
- true if foo equals bar within tolerance
-
formatDouble
Returns a formatted Double value given a specific DecimalFormat
If more than 4 integer, then we display the value in scientific notation- Parameters:
value-precision-- Returns:
- a double value formatted as a String
-
roundDouble
public static double roundDouble(double value, int precision) Method that rounds a value to the n precision decimals- Parameters:
value-precision-- Returns:
- a double value rounded to n precision
-
main
-