Example usage for java.text NumberFormat setMaximumFractionDigits

List of usage examples for java.text NumberFormat setMaximumFractionDigits

Introduction

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

Prototype

public void setMaximumFractionDigits(int newValue) 

Source Link

Document

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

Usage

From source file:Main.java

public static String getMatchingThresholdToString(int value) {
    double p = -value / 12.0;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(Math.max(0, (int) Math.ceil(-p) - 2));
    nf.setMinimumIntegerDigits(1);//from   w ww .  j a  v a 2s  .  c  om
    return nf.format(Math.pow(10, p));
}

From source file:Main.java

/**
 * Converts a length of bytes to MB./*from   w  w w  .j  a v  a  2s.  c o m*/
 * 
 * @param bytes
 *            The bytes to convert
 * @return A string representation of the MB
 */
public static String convertBytesToMB(long bytes) {
    double result = (double) bytes / 1000 / 1000;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    nf.setGroupingUsed(false);
    return nf.format(result) + " MB";
}

From source file:Main.java

public static String getPercentage(Integer i, Integer total) {
    if (i == 0) {
        return "0%/";
    }//from  w  w  w. j  a v  a  2 s .c o m
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setMaximumFractionDigits(1);
    return numberFormat.format((float) i / (float) total * 100) + "%/";
}

From source file:ubic.gemma.core.util.TimeUtil.java

public static String getMinutesElapsed(StopWatch overallWatch) {
    Long overallElapsed = overallWatch.getTime();
    NumberFormat nf = new DecimalFormat();
    nf.setMaximumFractionDigits(2);
    return nf.format(overallElapsed / (60.0 * 1000.0));
}

From source file:Main.java

public static String setLocaleNumberFormat(Locale locale, Number number) {

    NumberFormat formatter = NumberFormat.getInstance(locale);
    formatter.setMaximumFractionDigits(4);
    String localeFormattedNumber = formatter.format(number);
    return localeFormattedNumber;

}

From source file:ubic.gemma.util.TimeUtil.java

/**
 * @param overallWatch/* w  ww .jav a2 s  .  c o m*/
 * @return
 */
public static String getMinutesElapsed(StopWatch overallWatch) {
    Long overallElapsed = overallWatch.getTime();
    NumberFormat nf = new DecimalFormat();
    nf.setMaximumFractionDigits(2);
    String minutes = nf.format(overallElapsed / (60.0 * 1000.0));
    return minutes;
}

From source file:Main.java

public synchronized static String getPriceByFormat(float price) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMinimumFractionDigits(2);/*ww w.  j a va2  s.  co  m*/
    format.setMaximumFractionDigits(2);
    String priceNum = format.format(price);
    return priceNum;
}

From source file:Main.java

protected static String format(String value) {
    Double myNumber = Double.valueOf(value);
    NumberFormat format = NumberFormat.getInstance();
    format.setMinimumFractionDigits(3);/*w  ww  .j a v  a  2  s . co m*/
    format.setMaximumFractionDigits(3);
    format.setGroupingUsed(false);
    return format.format(myNumber);
}

From source file:Main.java

public static String formatStringTwoDecPercent(float number) {
    NumberFormat formatter = NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(0);
    formatter.setMaximumFractionDigits(2);

    return String.valueOf(formatter.format(number) + "%");
}

From source file:Main.java

public static String doubleToString(double d, int df) {
    String res = "";
    NumberFormat form;
    form = NumberFormat.getInstance(Locale.US);
    form.setMaximumFractionDigits(df);
    form.setGroupingUsed(false);/*from  ww  w.j  av  a 2 s  . c om*/
    try {
        res = form.format(d);
    } catch (IllegalArgumentException e) {
        res = "";
    }
    return res;
}