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

StringformatNumber(String Format, double Num)
Formats a number using DecimalFormat .
if (nf instanceof DecimalFormat)
    ((DecimalFormat) nf).applyPattern(Format);
return nf.format(Num);
StringformatNumber(String format, double number)
Converts the number into the specified format
if (format == null)
    return "" + number;
DecimalFormat df = new DecimalFormat(format);
String retVal = null;
try {
    retVal = df.format(number);
} catch (Exception e) {
    retVal = "" + number;
...
StringformatNumber(String number, int maxFractionalDigits)
Formats the provided number with the specified number of fractional digits If number arg is not a number, returns the String
try {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(maxFractionalDigits);
    return nf.format(Double.parseDouble(number));
} catch (Exception ex) {
    return number;
StringformatNumberAttribute(double v)
format Number Attribute
return format.format((float) v);
StringformatNumFraction(float num, int unit)
format Num Fraction
String zero = "";
if (unit == 0) {
    zero = "0";
} else {
    zero = "0.";
for (int i = 0; i < unit; i++) {
    zero += "0";
...
doubleformatNumValueWithComma(double val)
format Num Value With Comma
double formattedValue;
DecimalFormat formatter = new DecimalFormat("#,###,##0.00");
String newValue = formatter.format(val);
formattedValue = Double.parseDouble(newValue);
return formattedValue;
StringformatoDecimal(String tipo, double valor)
formato Decimal
String mascara = "0.";
if (tipo.equals("Q")) {
    for (int i = 0; i < DECIMAL_QUANTIDADE; i++) {
        mascara += "0";
} else if (tipo.equals("V")) {
    for (int i = 0; i < DECIMAL_VALOR; i++) {
        mascara += "0";
...
StringformatOLETime(double oleTime)
format OLE Time
long dateTime = getMillisFromOLEDate(oleTime);
return formatDateTime(dateTime);
StringformatOneDecimal(double dNumber)
format One Decimal
return ONEDP.format(dNumber);
StringformatOneDp(double inNumber)
format One Dp
return FORMAT_ONE_DP.format(inNumber);