Example usage for java.text NumberFormat getCurrencyInstance

List of usage examples for java.text NumberFormat getCurrencyInstance

Introduction

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

Prototype

public static NumberFormat getCurrencyInstance(Locale inLocale) 

Source Link

Document

Returns a currency format for the specified locale.

Usage

From source file:Main.java

public static String toReal(Double value) {
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));
    return numberFormat.format(value).replace("R$", "R$ ");
}

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);
    }//from  www  .j  av a  2s  . c  om

    amountTxt = amountTxtValue;

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

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 . ja  v a  2 s  .com

    amountTxt = amountTxtValue;

    return (amountTxt);
}

From source file:Main.java

public static String formatMoneyAmountItemised(double amount, Locale locale) {

    NumberFormat format = NumberFormat.getCurrencyInstance(locale);

    format.setMinimumFractionDigits(0);//  ww w . j  a  v  a  2s. c om
    format.setMaximumFractionDigits(3);

    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);
    }

    amountTxt = amountTxtValue;

    if (amountTxt.endsWith(",0"))
        return (amountTxt.replace(",0", ""));
    else if (amountTxt.endsWith(",00"))
        return (amountTxt.replace(",00", ""));
    else if (amountTxt.endsWith(",000"))
        return (amountTxt.replace(",000", ""));
    else
        return (amountTxt);

}

From source file:Main.java

public static String formatMoneyAmountOne(double amount) {
    Locale locale = new Locale("ru", "RU");
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);
    format.setMinimumFractionDigits(0);//from   ww w .  ja v a2  s  .c om
    format.setMaximumFractionDigits(1);
    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);
    }

    amountTxt = amountTxtValue;

    if (amountTxt.endsWith(",00"))
        return (amountTxt.replace(",00", ""));
    else if (amountTxt.endsWith("0") && amountTxt.contains(",")) {
        return (amountTxt.substring(0, amountTxt.length() - 1));
    } else
        return (amountTxt);
}

From source file:Main.java

public static boolean isRTL(Locale locale, String symbol) {
    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);

    // We then tell our formatter to use this symbol.
    DecimalFormatSymbols decimalFormatSymbols = ((java.text.DecimalFormat) currencyFormat)
            .getDecimalFormatSymbols();/*from   w ww.  j a v a 2 s .com*/
    decimalFormatSymbols.setCurrencySymbol(symbol);
    ((java.text.DecimalFormat) currencyFormat).setDecimalFormatSymbols(decimalFormatSymbols);

    String formattedtext = currencyFormat.format(100.0);

    if (formattedtext.startsWith(symbol)) {
        return false;
    } else {
        return true;
    }

    /*
    final int directionality = Character.getDirectionality(String.format(locale,"%s",locale.getDisplayLanguage(locale)).charAt(0));
            
    if ( (directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT) ||
        (directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) )
    {
    return true;
    }
    else
    {
    return false;
    }
     */
}

From source file:Main.java

public static String convertToCurrency(float value) {
    DecimalFormat format = new DecimalFormat("#.##");
    try {/*  www  . ja  va 2  s  .co  m*/
        value = Float.parseFloat(format.format(value));
    } catch (Exception e) {
        e.printStackTrace();
    }
    NumberFormat defaultFormat = NumberFormat.getCurrencyInstance(Locale.CANADA);
    return defaultFormat.format(value);
}

From source file:Main.java

public static String formatCurrency(double amount, int precision, String pattern, Locale locale) {
    NumberFormat nf = NumberFormat.getCurrencyInstance(locale);
    DecimalFormat df = (DecimalFormat) nf;
    df.setMinimumFractionDigits(precision);
    df.setMaximumFractionDigits(precision);
    df.setDecimalSeparatorAlwaysShown(true);
    df.applyPattern(pattern);/*from  w w w.  j  a  v  a2s  . com*/
    return df.format(amount);
}

From source file:com.squarespace.template.plugins.platform.PlatformUtils.java

/**
 * Like money-format (e.g. 0.00) but with a currency (dollar) sign and parentheses on negative values.
 * Fully internationalized. Uses NumberFormat under the hood.
 *///from w  w w . j a  v  a 2 s .  co m
public static String formatBookkeeperMoney(double cents, Locale locale) {
    NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
    return formatter.format(cents / 100);
}