Example usage for java.text NumberFormat setMinimumFractionDigits

List of usage examples for java.text NumberFormat setMinimumFractionDigits

Introduction

In this page you can find the example usage for java.text NumberFormat setMinimumFractionDigits.

Prototype

public void setMinimumFractionDigits(int newValue) 

Source Link

Document

Sets the minimum number of digits allowed in the fraction portion of a number.

Usage

From source file:com.nextgis.maplibui.fragment.CompassFragment.java

public static String formatNumber(Object value, int max, int min) {
    NumberFormat f = NumberFormat.getInstance();
    f.setMaximumFractionDigits(max);//from   w ww .j a  v a  2  s. c  om
    f.setMinimumFractionDigits(min);
    f.setGroupingUsed(false);

    try {
        return f.format(value);
    } catch (IllegalArgumentException e) {
        return e.getLocalizedMessage();
    }
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static CharSequence formatCount(long count, boolean isUserCount) {
    // TODO Auto-generated method stub
    if (count < 1000) {
        return String.valueOf(count);
    } else {//w  ww.  ja  v a2s .  c  o  m
        String result = null;

        NumberFormat df = DecimalFormat.getInstance();
        df.setRoundingMode(RoundingMode.DOWN);

        double countWithK = count / 1000.0;
        if (isUserCount) {
            df.setMinimumFractionDigits(0);
            df.setMaximumFractionDigits(0);
        } else {
            df.setMinimumFractionDigits(1);
            df.setMaximumFractionDigits(1);
        }
        result = df.format(countWithK);
        result = result + "K";
        return result;
    }

}

From source file:us.fatehi.pointlocation6709.format.PointLocationFormatter.java

private static NumberFormat getNumberFormat(final int integerDigits) {
    final NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setMinimumIntegerDigits(integerDigits);
    numberFormat.setMinimumFractionDigits(5);
    numberFormat.setMaximumFractionDigits(5);
    numberFormat.setGroupingUsed(false);
    return numberFormat;
}

From source file:org.apache.nifi.schemaregistry.processors.CSVUtils.java

/**
 * According to the 1.7.7 spec If a logical type is invalid, for example a
 * decimal with scale greater than its precision,then implementations should
 * ignore the logical type and use the underlying Avro type.
 *///  ww w  .j a  v  a 2s . com
private static void normalizeNumberFormat(NumberFormat numberFormat, int scale, int precision) {
    if (scale < precision) {
        // write out with the specified precision and scale.
        numberFormat.setMaximumIntegerDigits(precision);
        numberFormat.setMaximumFractionDigits(scale);
        numberFormat.setMinimumFractionDigits(scale);
    }
}

From source file:org.projectforge.common.NumberHelper.java

public static NumberFormat getNumberFraction2Format(final Locale locale) {
    final NumberFormat format = NumberFormat.getNumberInstance(locale);
    format.setMaximumFractionDigits(2);/*w  w w .  ja  v a2s  . co  m*/
    format.setMinimumFractionDigits(2);
    return format;
}

From source file:org.projectforge.common.NumberHelper.java

public static NumberFormat getNumberFractionFormat(final Locale locale, final int fractionDigits) {
    final NumberFormat format = NumberFormat.getNumberInstance(locale);
    format.setMaximumFractionDigits(fractionDigits);
    format.setMinimumFractionDigits(fractionDigits);
    return format;
}

From source file:org.totschnig.myexpenses.util.Utils.java

static String formatCurrency(BigDecimal amount, Currency currency) {
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    int fractionDigits = currency.getDefaultFractionDigits();
    nf.setCurrency(currency);//from w  w w  . ja  va 2 s .  c o  m
    nf.setMinimumFractionDigits(fractionDigits);
    nf.setMaximumFractionDigits(fractionDigits);
    return nf.format(amount);
}

From source file:org.squale.squaleweb.util.SqualeWebActionUtils.java

/**
 * Factorisation de code, aucun test n'est fait
 * //from ww  w. j  av a 2s .  c  o m
 * @param pFloat le float  formater
 * @return la chaine associe au float
 */
private static String formatFloat(float pFloat) {
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(1);
    nf.setMinimumFractionDigits(1);
    String result = nf.format(pFloat);
    return result;
}

From source file:org.yawlfoundation.yawl.util.StringUtil.java

/**
 * Utility routine which takes a decimal value as a string (e.g. 0.25 equating to 25p) and returns the
 * value in UI currency format (e.g. 0.25).
 *
 * @return A formatted currency//from w w w .  j a  v  a 2s  . c o m
 */
public static String formatDecimalCost(BigDecimal value) {
    Currency currency = Currency.getInstance(Locale.getDefault());
    NumberFormat fmt = DecimalFormat.getInstance();
    fmt.setMinimumFractionDigits(2);
    fmt.setMaximumFractionDigits(2);
    return currency.getSymbol() + fmt.format(value);
}

From source file:com.cubusmail.mail.util.MessageUtils.java

/**
 * @param locale/* w  ww  . j ava 2  s  .  c  o m*/
 * @return
 */
public static NumberFormat createSizeFormat(Locale locale) {

    NumberFormat sizeFormat = DecimalFormat.getNumberInstance(locale);
    sizeFormat.setGroupingUsed(true);
    sizeFormat.setMaximumFractionDigits(0);
    sizeFormat.setMinimumFractionDigits(0);

    return sizeFormat;
}