I have float = 11.6
want to convert into Brazilian currency R$ 11,60
, does anyone know how to do?
I have float = 11.6
want to convert into Brazilian currency R$ 11,60
, does anyone know how to do?
I usually use the getCurrencyInstance with locale set manually because when I do not set it it picks up the operating system time and can certainly do a wrong conversion from real to dollar for example.
Double d = 10.1;
Locale ptBr = new Locale("pt", "BR");
String valorString = NumberFormat.getCurrencyInstance(ptBr).format(d);
System.out.println(valorString);
There are a few ways to do it, for example:
BigDecimal valor = new BigDecimal ("12000000.12");
NumberFormat nf = NumberFormat.getCurrencyInstance();
String formatado = nf.format (valor);
System.out.println(formatado);
//O resultado é R$ 12.000.000,12
Another option:
Long a = Long.parseLong("999999999999999999");
System.out.println(NumberFormat.getCurrencyInstance().format(a));
//saída R$ 999.999.999.999.999.999,00