Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:Main.java

public static String saveNumberPercent(float number) {
    NumberFormat nt = NumberFormat.getPercentInstance();
    nt.setMinimumFractionDigits(2);//from   www  .j  av a2s .c om
    return nt.format(number);
}

From source file:Main.java

public static String toPercentDigital(double d) {
    NumberFormat nt = NumberFormat.getPercentInstance();
    nt.setMinimumFractionDigits(2);//from   ww  w  .  ja v  a  2 s . c o  m
    return nt.format(d);
}

From source file:Main.java

public static String formatMoneyAmountBills(double amount, Locale locale) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);

    String amountTxt = format.format(amount);
    String amountTxtValue = "";
    for (int i = 0; i < amountTxt.length(); i++) {
        if (Character.isDigit(amountTxt.charAt(i)) || amountTxt.charAt(i) == '.' || amountTxt.charAt(i) == ',')
            amountTxtValue = amountTxtValue + amountTxt.charAt(i);
    }/*from ww w  .j  a v a2 s.  c o m*/

    amountTxt = amountTxtValue;

    return (amountTxt);
}

From source file:Main.java

public static String percent(double p1, double p2) {
    String str;/*from  w  ww .  j  a va  2  s .c om*/
    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  www. j  a v  a 2  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 doubleToString(double v) {
    java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
    nf.setGroupingUsed(false);//  w  w w . j a  v  a  2  s  .  co m
    return nf.format(v);
}

From source file:Main.java

public static String convertToCurrencyFormat(String amount) {
    double amountDouble = Double.parseDouble(amount);
    NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
    String returnString = formatter.format(amountDouble).replace("Rs.", "");
    return returnString.replace("Rs", "").trim();
}

From source file:Main.java

public static String formatMoneyAmount(double amount, Locale locale) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);

    String amountTxt = format.format(amount);
    String amountTxtValue = "";
    for (int i = 0; i < amountTxt.length(); i++) {
        if (Character.isDigit(amountTxt.charAt(i)) || amountTxt.charAt(i) == '.' || amountTxt.charAt(i) == ',')
            amountTxtValue = amountTxtValue + amountTxt.charAt(i);
    }//w ww.  ja v  a 2  s.c  o m

    amountTxt = amountTxtValue;

    if (amountTxt.endsWith(",00"))
        return (amountTxt.replace(",00", ""));
    return (amountTxt);
}

From source file:Main.java

public static String getPageFileName(int p) {
    NumberFormat nf = NumberFormat.getInstance(Locale.US);
    nf.setMinimumIntegerDigits(3);//  w ww  . jav  a2 s  .  c o m
    return "page" + nf.format(p) + ".png";
}

From source file:Main.java

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