Class DoubleFormat

java.lang.Object
edu.cnu.mdi.format.DoubleFormat

public final class DoubleFormat extends Object
Thread-safe helpers for fixed-point and scientific decimal formatting.
  • Method Details

    • doubleFormat

      public static String doubleFormat(double value, int numdec)
      Format a double
      Parameters:
      value - the value to format.
      numdec - the number of digits right of the decimal.
      Returns:
      the formatted value
      Throws:
      IllegalArgumentException - if numdec is outside 0 through 100
    • doubleFormat

      public static String doubleFormat(double value, int numdec, boolean scinot)
      Format a double
      Parameters:
      value - the value to format.
      numdec - the number of digits right of the decimal.
      scinot - if true, use scientific notation.
      Returns:
      the formatted value
      Throws:
      IllegalArgumentException - if numdec is outside 0 through 100
    • doubleFormat

      public static String doubleFormat(double value, int numdec, int minExponent)
      Format a double, using scientific notation once its magnitude's order-of-magnitude exponent reaches the specified minimum.

      The exponent is computed from log10(|value|). Values with magnitude less than 1 are treated symmetrically: an exponent of, e.g., -3 (for a value like 0.001) is remapped to 4 before comparison, so very small values trigger scientific notation the same way very large ones do. Non-scientific (fixed-point) notation is used while the (remapped) exponent stays below minExponent.

      Parameters:
      value - the value to format.
      numdec - the number of digits right of the decimal.
      minExponent - the exponent at (and above) which scientific notation is used.
      Returns:
      the formatted value
      Throws:
      IllegalArgumentException - if numdec is outside 0 through 100