Package edu.cnu.mdi.format
Class DoubleFormat
java.lang.Object
edu.cnu.mdi.format.DoubleFormat
Thread-safe helpers for fixed-point and scientific decimal formatting.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringdoubleFormat(double value, int numdec) Format a doublestatic StringdoubleFormat(double value, int numdec, boolean scinot) Format a doublestatic StringdoubleFormat(double value, int numdec, int minExponent) Format a double, using scientific notation once its magnitude's order-of-magnitude exponent reaches the specified minimum.
-
Method Details
-
doubleFormat
Format a double- Parameters:
value- the value to format.numdec- the number of digits right of the decimal.- Returns:
- the formatted value
- Throws:
IllegalArgumentException- ifnumdecis outside 0 through 100
-
doubleFormat
Format a double- Parameters:
value- the value to format.numdec- the number of digits right of the decimal.scinot- iftrue, use scientific notation.- Returns:
- the formatted value
- Throws:
IllegalArgumentException- ifnumdecis outside 0 through 100
-
doubleFormat
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 like0.001) is remapped to4before 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 belowminExponent.- 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- ifnumdecis outside 0 through 100
-