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:Main.java

public static String saveNumberPercent(float number) {
    NumberFormat nt = NumberFormat.getPercentInstance();
    nt.setMinimumFractionDigits(2);
    return nt.format(number);
}

From source file:Main.java

public static String toPercentDigital(double d) {
    NumberFormat nt = NumberFormat.getPercentInstance();
    nt.setMinimumFractionDigits(2);
    return nt.format(d);
}

From source file:Main.java

public synchronized static String getPriceByFormat(float price) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMinimumFractionDigits(2);
    format.setMaximumFractionDigits(2);// ww w . ja  va 2  s.c om
    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);
    format.setMaximumFractionDigits(3);/*from   w w w  . j ava 2 s  . c  o  m*/
    format.setGroupingUsed(false);
    return format.format(myNumber);
}

From source file:Main.java

public static String percent(double p1, double p2) {
    String str;//from w ww  .jav a  2 s .c  o  m
    double p3 = p1 / p2;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(2);
    str = nf.format(p3);
    return str;
}

From source file:Main.java

public static String percent2(double p1, double p2) {
    String str;/*from w  w  w  . ja  va2  s  .  c  o  m*/
    double p3 = p1 / p2;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMinimumFractionDigits(0);
    str = nf.format(p3);
    return str;
}

From source file:Main.java

public static String formatInteger2String(Integer formater) {
    try {//from w ww  . j  a  v  a2 s .  c om
        NumberFormat nbf = NumberFormat.getInstance();
        nbf.setMinimumFractionDigits(0);
        return nbf.format(formater);
    } catch (Exception e) {
        // TODO: handle exception
        return "-";
    }
}

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:com.example.awesomedogs.util.Stuff.java

/**
 * Converts some currency cents to a more readable format.
 * //from  ww  w.  j  a  v  a 2 s.  c om
 * @param cents Amount in cents, e.g. 123.
 * @return Formatted value, e.g. "1.23".
 */
public static String formatCents(int cents) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(2);
    nf.setMaximumFractionDigits(2);
    return nf.format(((double) cents / 100));
}

From source file:Main.java

public static String formatNumber(double amount, int precision, Locale locale) {
    NumberFormat nf = NumberFormat.getNumberInstance(locale);
    nf.setMinimumFractionDigits(precision);
    nf.setMaximumFractionDigits(precision);
    return nf.format(amount);
}