List of usage examples for java.text NumberFormat getCurrencyInstance
public static NumberFormat getCurrencyInstance(Locale inLocale)
From source file:com.cloudbees.demo.beesshop.cart.ShoppingCart.java
/** * Price in dollars/*from w w w .j a v a 2 s . c om*/ */ public String getPrettyPrice() { BigDecimal priceInDollars = new BigDecimal(getPriceInCents()).movePointLeft(2); return NumberFormat.getCurrencyInstance(Locale.US).format(priceInDollars); }
From source file:org.techytax.helper.AmountHelper.java
public static String formatDecimal(BigInteger b) { Locale loc = new Locale("nl", "NL", "EURO"); NumberFormat n = NumberFormat.getCurrencyInstance(loc); double doublePayment = b.doubleValue(); n.setMaximumFractionDigits(0);//from w w w. j av a2 s. c o m String s = n.format(doublePayment); return s; }
From source file:com.ibk.ltw.domain.Product.java
public String getNetPriceAsText() { BigDecimal netPriceInDollars = new BigDecimal(getNetPriceInCents()).movePointLeft(2); return NumberFormat.getCurrencyInstance(Locale.US).format(netPriceInDollars); }
From source file:fr.cph.stock.android.entity.EntityBuilder.java
private void buildUser() throws JSONException { user = new User(); JSONObject jsonUser = json.getJSONObject("user"); String userIdStr = jsonUser.getString("id"); user.setUserId(userIdStr);/* w w w .jav a 2s.co m*/ String localeStr = jsonUser.getString("locale"); String language = localeStr.split("_")[0]; String country = localeStr.split("_")[1]; Locale locale = new Locale(language, country); user.setLocale(locale); formatCurrencyZero = NumberFormat.getCurrencyInstance(user.getLocale()); formatCurrencyZero.setMaximumFractionDigits(0); formatCurrencyZero.setMinimumFractionDigits(0); formatCurrencyZero.setRoundingMode(RoundingMode.HALF_DOWN); formatCurrencyOne = NumberFormat.getCurrencyInstance(user.getLocale()); formatCurrencyOne.setMaximumFractionDigits(1); formatCurrencyOne.setMinimumFractionDigits(0); formatCurrencyOne.setRoundingMode(RoundingMode.HALF_DOWN); formatCurrencyTwo = NumberFormat.getCurrencyInstance(user.getLocale()); formatCurrencyTwo.setMaximumFractionDigits(2); formatCurrencyTwo.setMinimumFractionDigits(0); formatCurrencyTwo.setRoundingMode(RoundingMode.HALF_DOWN); formatLocaleZero = NumberFormat.getInstance(user.getLocale()); formatLocaleZero.setMaximumFractionDigits(0); formatLocaleZero.setMinimumFractionDigits(0); formatLocaleZero.setRoundingMode(RoundingMode.HALF_DOWN); formatLocaleOne = NumberFormat.getInstance(user.getLocale()); formatLocaleOne.setMaximumFractionDigits(1); formatLocaleOne.setMinimumFractionDigits(0); formatLocaleOne.setRoundingMode(RoundingMode.HALF_DOWN); formatLocaleTwo = NumberFormat.getInstance(user.getLocale()); formatLocaleTwo.setMaximumFractionDigits(2); formatLocaleTwo.setMinimumFractionDigits(0); formatLocaleTwo.setRoundingMode(RoundingMode.HALF_DOWN); String datePattern = jsonUser.getString("datePattern"); user.setDatePattern(datePattern); String datePatternWithoutHourMin = jsonUser.getString("datePatternWithoutHourMin"); user.setDatePatternWithoutHourMin(datePatternWithoutHourMin); JSONObject lastUpdateJSON = jsonUser.getJSONObject("lastUpdate"); user.setLastUpdate(extractDate(lastUpdateJSON, user.getDatePattern())); }
From source file:info.curtbinder.farmgame.GameActivity.java
public static String getCurrencyFormattedString(int value) { NumberFormat nft = NumberFormat.getCurrencyInstance(Locale.getDefault()); nft.setMaximumFractionDigits(0);/*from w w w . jav a2 s. c o m*/ return nft.format(value); }
From source file:com.codebutler.farebot.transit.MensacardTransitData.java
@Override public String getBalanceString() { return NumberFormat.getCurrencyInstance(Locale.GERMANY).format((double) mBalance / 1000) + "\n" + NumberFormat.getCurrencyInstance(Locale.GERMANY).format((double) lastTransaction / 1000); }
From source file:com.carser.viamais.entity.Transaction.java
public void generateReceipt(final OutputStream os, final String template) throws IOException, DocumentException { reader = new PdfReader(this.getClass().getResourceAsStream("/receipts/" + template)); stamper = new PdfStamper(reader, os); form = stamper.getAcroFields();// w w w . j a v a 2 s .co m brazilLocale = new Locale("pt", "BR"); formatter = NumberFormat.getCurrencyInstance(brazilLocale); // Customer data Customer customer = getCustomer(); form.setField("CUSTOMER_NAME", customer.getName().toUpperCase()); form.setField("CUSTOMER_CPF", StringUtil.formatCPF(customer.getCpf())); form.setField("CUSTOMER_RG", customer.getRg().toUpperCase()); // Addres data Address address = customer.getAddresses().get(0); StringBuilder addressDescription = new StringBuilder(); addressDescription.append(address.getStreet()); addressDescription.append(", " + address.getNumber()); if (address.getComplement() != null) { addressDescription.append(", " + address.getComplement()); } form.setField("CUSTOMER_ADDRESS", addressDescription.toString().toUpperCase()); form.setField("CUSTOMER_DISTRICT", address.getDistrict().toUpperCase()); form.setField("CUSTOMER_CEP", address.getCep()); form.setField("CUSTOMER_CITY", address.getCity().toUpperCase()); form.setField("CUSTOMER_STATE", address.getState().toUpperCase()); List<Phone> phones = customer.getPhones(); for (Phone phone : phones) { String phoneNumber = StringUtil.formatPhone(Long.valueOf(phone.getPrefix() + "" + phone.getNumber())); switch (phone.getType()) { case "Celular": form.setField("CUSTOMER_CELLPHONE", phoneNumber); break; case "Residencial": form.setField("CUSTOMER_PHONE", phoneNumber); break; case "Comercial": form.setField("CUSTOMER_COMPHONE", phoneNumber); break; default: break; } } // Car data Car car = getCar(); form.setField("CAR_MANUFACTURER", car.getModel().getManufacturer().getName().toUpperCase()); form.setField("CAR_MODEL", car.getModel().getName().toUpperCase()); form.setField("CAR_YEAR", car.getYearOfManufacture() + "/" + car.getYearOfModel()); form.setField("CAR_COLOR", car.getColor().toUpperCase()); form.setField("CAR_PLATE", car.getLicensePlate().toUpperCase()); form.setField("CAR_CHASSI", car.getChassi().toUpperCase()); form.setField("CAR_RENAVAM", car.getRenavam().toUpperCase()); // Transaction data form.setField("CAR_DEPOSIT", formatter.format(getDeposit()) + " (" + StringUtil.formatCurrency(getDeposit()) + ")"); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.LONG, brazilLocale); form.setField("CAR_VALUE", formatter.format(getPrice()) + " (" + StringUtil.formatCurrency(getPrice()) + ")"); form.setField("DATE", dateFormatter.format(new Date())); DateFormat deliveryDateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, brazilLocale); DateFormat deliveryTimeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, brazilLocale); if (getDeliveryDate() != null) { form.setField("DELIVERY_DATE", deliveryDateFormatter.format(getDeliveryDate()) + " " + deliveryTimeFormatter.format(getDeliveryDate())); } if (getKm() != null) { form.setField("DELIVERY_KM", getKm().toString()); } }
From source file:com.rasrin.locale.formatter.plugin.LocaleFormatter.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {// www .j a v a 2 s . co m if (action.equals("formatCurrency")) { if (args.length() < 3) { callbackContext.error("Expected 3 arguments."); return false; } String ilocale = args.getString(0); long amount = args.getLong(1); boolean debug = args.getBoolean(2); Locale locale = new Locale("en", "US"); if (ilocale != null && ilocale.length() <= 5) { if (ilocale.indexOf('-') > 0) { String[] parts = ilocale.split("-"); locale = new Locale(parts[0], parts[1]); } } NumberFormat formatter = NumberFormat.getCurrencyInstance(locale); String moneyString = formatter.format(amount); if (debug) { System.out.println("Called with locale: " + ilocale + " & amount: " + amount + ". Formatted string is: " + moneyString); } callbackContext.success(moneyString); return true; } else { callbackContext.error("Unsupported operation"); return false; } } catch (Exception ex) { callbackContext.error("Something went wrong: " + ex.getMessage()); return false; } }
From source file:com.ibk.ltw.domain.Product.java
/** * <code>grossPriceInCents * (1 + (vatInPercent / 100))</code> * * @return Price with VAT/*w ww. j a va 2 s . co m*/ */ public String getGrossPriceAsText() { BigDecimal grossPriceInDollars = new BigDecimal(getGrossPriceInCents()).movePointLeft(2); return NumberFormat.getCurrencyInstance(Locale.US).format(grossPriceInDollars); }
From source file:com.erudika.para.i18n.CurrencyUtils.java
/** * Formats a price for its specific locale, depending on the currency code * @param price the amount/*from ww w .j av a 2s .com*/ * @param cur the 3-letter currency code * @return a formatted price with its currency symbol */ public String formatPrice(Double price, String cur) { String formatted = ""; if (price != null) { Locale locale = CURRENCY_TO_LOCALE_MAP.get(cur); NumberFormat f = (locale == null) ? NumberFormat.getCurrencyInstance(Locale.US) : NumberFormat.getCurrencyInstance(locale); f.setMinimumFractionDigits(2); formatted = f.format(price); } return formatted; }