Class DoubleUtils

java.lang.Object
org.dawb.common.util.number.DoubleUtils

public class DoubleUtils extends Object
  • Constructor Details

    • DoubleUtils

      public DoubleUtils()
  • Method Details

    • equalsWithinTolerance

      public static boolean equalsWithinTolerance(Number foo, Number bar, Number tolerance)
      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

      public static String formatDouble(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 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

      public static void main(String[] args)