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

Stringformat(double val)
Format decimals to 4 digits only
return new String(df.format(val));
Stringformat(double val)
format
return format(val, DEFAULT_NUMBER_DIGIT);
Stringformat(double val)
format
if (Double.isNaN(val)) {
    return "?";
double absVal = Math.abs(val);
if (absVal > 1)
    formatter.setMaximumFractionDigits(1);
else {
    double log = Math.log10(absVal);
...
Stringformat(double value)
format
return format.format(value);
Stringformat(double value)
Format a map scale into a string
return String.format("%s%s", SCALE_PREFIX, NumberFormat.getIntegerInstance().format((int) value));
Stringformat(double value)
format
final Double doubleValue = new Double(value);
final int intValue = doubleValue.intValue();
if (intValue == value) {
    return Integer.toString(intValue);
return FORMATTER.format(value);
Stringformat(double value)
format
value = round(value);
NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
return format.format(value).replaceAll(",", "");
Stringformat(double value)
format
DecimalFormat format = new DecimalFormat("0.00");
DecimalFormatSymbols instance = DecimalFormatSymbols.getInstance();
instance.setDecimalSeparator('.');
format.setDecimalFormatSymbols(instance);
return format.format(value);
Stringformat(double value, double unit)
format
int dotIndex = (unit + "").indexOf('.');
if (dotIndex == -1) {
    return value + "";
} else {
    int dotDigits = (unit + "").length() - dotIndex - 1;
    String pattern = "#.";
    for (int i = 0; i < dotDigits; i++) {
        pattern += "0";
...
Stringformat(double value, int decimalPlace)
Format the given value to the number of decimal places specified.
NumberFormat nft = NumberFormat.getInstance();
nft.setMinimumFractionDigits(decimalPlace);
nft.setMaximumFractionDigits(decimalPlace);
return nft.format(value);