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

StringformatNum(double num, int numfracdigits)
format Num
if (numberFormat == null) {
    numberFormat = NumberFormat.getInstance();
    numberFormat.setGroupingUsed(false);
numberFormat.setMinimumFractionDigits(numfracdigits);
numberFormat.setMaximumFractionDigits(numfracdigits);
return numberFormat.format(num);
floatformatNum(float value)
format Num
DecimalFormat df1 = new DecimalFormat("###.00");
return Float.parseFloat(df1.format(value));
StringformatNumber(double decimal)
format Number
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
symbols.setGroupingSeparator(' ');
symbols.setDecimalSeparator(',');
DecimalFormat formatter = new DecimalFormat("###,###.###", symbols);
formatter.setMaximumFractionDigits(3);
formatter.setMinimumFractionDigits(3);
return formatter.format(decimal);
CharSequenceformatNumber(double i)
format Number
return NumberFormat.getInstance().format(i);
StringformatNumber(double num)
Show a reasonable number of significant digits.
double absnum = Math.abs(num);
if (absnum == 0) {
    return "0";
if (absnum > 10000000.0 || absnum < 0.000000001) {
    return expFormat_.format(num);
if (absnum > 1000.0) {
...
StringformatNumber(double num)
format Number
return java.text.NumberFormat.getNumberInstance().format(num);
StringformatNumber(double number)
format Number
return formatNumber(number, "0.00");
StringformatNumber(double number)
Formats a number, as a decimal number with at most 2 digits.
return DECIMAL.format(number);
StringformatNumber(double number, int decimal)
format Number
NUM_FORMAT.setMaximumFractionDigits(decimal);
NUM_FORMAT.setMinimumFractionDigits(decimal);
return NUM_FORMAT.format(number).replace(",", "");
StringformatNumber(double number, int val)
format Number
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(val);
nf.setMinimumFractionDigits(val);
nf.setRoundingMode(RoundingMode.HALF_UP);
nf.setGroupingUsed(false);
return nf.format(number);