Here you can find the source of stringToReais(String unformatted, boolean comSimbolo)
public static String stringToReais(String unformatted, boolean comSimbolo)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.Locale; public class Main { public static String stringToReais(String unformatted, boolean comSimbolo) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale("pt", "BR")); symbols.setGroupingSeparator('.'); symbols.setDecimalSeparator(','); if (!comSimbolo) { symbols.setCurrencySymbol(""); }//from ww w .j av a 2 s . co m DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("pt", "BR")); // DecimalFormat decimalFormat= new DecimalFormat("#,##0.0#", symbols); <-- erra decimalFormat.setDecimalFormatSymbols(symbols); decimalFormat.setParseBigDecimal(true); decimalFormat.setMinimumFractionDigits(2); return decimalFormat.format(unformatted).trim(); } }