Java Utililty Methods Fraction Format

List of utility methods to do Fraction Format

Description

The list of methods to do Fraction Format are organized into topic(s).

Method

StringformatDecimals(double number)
format Decimals
return new DecimalFormat().format(number);
StringformatDecNumber(Double number, String pattern)
format Dec Number
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setDecimalSeparatorAlwaysShown(false);
if (number == null) {
    number = 0.0;
if (pattern == null || "".equals(pattern)) {
    pattern = NUMBER_PATTERN_1;
} else {
...
StringformatDegToDms(double degrees, double min, double max)
format Deg To Dms
String s = "";
double deg = normalizeAngle(degrees, min, max);
if (deg < 0) {
    deg = Math.abs(deg);
    s += "-";
double arcmin = (deg - (int) deg) * 60.0;
double arcsec = (arcmin - (int) arcmin) * 60.0;
...
StringformatDisplay(Double value)
format Display
return DECIMAL_FORMAT.format(value);
StringformatDistance(float distance)
Formatea la distancia con 2 decimales
DecimalFormat df = new DecimalFormat("###.##");
return df.format(distance) + " m";
StringformatDollarAmount(float amount)
format Dollar Amount
return decimalFormat.format(amount);
StringformatDoube(double val)
This method is used to format the value to 2 decimal places if val is 800.0 then this method will return 800.00 if val is 800.136 then this method will return 800.14
return doubleStringFormat.format(String.valueOf(val));
StringformatDouble(DecimalFormat fmt, double value)
format Double
if (Double.isNaN(value)) {
    return "NaN";
} else if (Double.isInfinite(value)) {
    if (value > 0) {
        return "+Inf";
    } else {
        return "-Inf";
} else {
    return fmt.format(value);
StringformatDouble(Double amount, String format)
format Double
DecimalFormat formatter = new DecimalFormat(format);
return formatter.format(amount);
StringformatDouble(double aValue)
format Double
DecimalFormat formatter = new DecimalFormat();
formatter.setGroupingUsed(false);
formatter.setMinimumIntegerDigits(1);
formatter.setMaximumFractionDigits(100);
formatter.setRoundingMode(RoundingMode.DOWN);
DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
symbols.setDecimalSeparator('.');
formatter.setDecimalFormatSymbols(symbols);
...