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

StringformatDataValue(double value)
format Data Value
NumberFormat dataValueFormat = new DecimalFormat("0");
return dataValueFormat.format(value);
StringformatDecimal(double dtSource, String nbit)
format Decimal
java.text.DecimalFormat formatter = null;
try {
    formatter = new java.text.DecimalFormat("#,###." + nbit);
} catch (Exception e) {
    System.out.println(e.getMessage());
return formatter.format(dtSource);
StringformatDecimal(double number)
format Decimal
NumberFormat format = NumberFormat.getInstance();
format.setMaximumIntegerDigits(Integer.MAX_VALUE);
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(2);
return format.format(number);
StringformatDecimal(double numToFormat)
format Decimal
return decimalFormatter.format(numToFormat);
StringformatDecimal(double value)
format Decimal
String result1;
result1 = nf.format(value); 
return result1;
StringformatDecimal(double value, int maxFractionDigits1, int maxFractionDigits2)
format Decimal
formatter.setMaximumFractionDigits(maxFractionDigits1);
formatter2.setMaximumFractionDigits(maxFractionDigits2);
if (value > 0 && (Math.abs(value) < 0.001 || Math.abs(value) >= 100000.0)) {
    return formatter.format(value);
} else {
    return formatter2.format(value);
StringformatDecimal(double value, int precision)
Format decimal string.
DecimalFormat df = getDecimalFormat(precision, "#");
return df.format(value);
StringformatDecimal(double value, String mask)
Formata um decimal, de acordo com a mascara.
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator(',');
dfs.setGroupingSeparator('.');
DecimalFormat df = new DecimalFormat(mask, dfs);
return df.format(value);
StringformatDecimal(String format, double value)
format Decimal
DecimalFormat df = new DecimalFormat(format);
return df.format(value);
doubleformatDecimals(double d, int mantissa)
Change the precision of a double value, according to the new mantissa.
String m = "";
for (int i = 0; i < mantissa; i++) {
    m += "#";
DecimalFormat decimalForm = new DecimalFormat("#." + m);
return Double.valueOf(decimalForm.format(d));