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(float number, int bitCount)
format
String result = "";
String strbit = "";
for (int i = 0; i < bitCount; i++) {
    strbit += "0";
java.text.DecimalFormat df = new java.text.DecimalFormat("#." + strbit);
result = df.format(number);
return result;
...
Stringformat(float totalNumberOfFreeBytes)
format
NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(1);
format.setMinimumFractionDigits(0);
if (totalNumberOfFreeBytes < 1024)
    return format.format(totalNumberOfFreeBytes) + " Bytes";
totalNumberOfFreeBytes = totalNumberOfFreeBytes / 1024;
if (totalNumberOfFreeBytes < 1024)
    return format.format(totalNumberOfFreeBytes) + " KB";
...
Stringformat(float value)
Formats a floating point value with useful default rules; ie.
return _ffmt.format(value);
Stringformat(NumberFormat nf, float number, float defaultValue)
format
if ((Float.isNaN(number)) || (Float.isInfinite(number))) {
    return nf.format(defaultValue);
} else {
    return nf.format(number);
Stringformat0(Double d)
format
if (d == null)
    return "";
return df0.format(d);
Stringformat2Double(Double amount)
format Double
return formatDouble(amount, "0.00");
StringformatAmount(double amount)
format Amount
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(0);
nf.setGroupingUsed(false);
return nf.format(amount);
StringformatAmount(Double amount)
format Amount
return String.format("%.2f", amount);
StringformatAmount(double number)
Creates a formatted string from the number input.
NumberFormat numberFormatter = NumberFormat.getCurrencyInstance();
String formattedString = numberFormatter.format(number);
return formattedString;
StringformatAmount(final double mark)
Format amount.
final DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
format.setMaximumFractionDigits(2);
return format.format(mark);