Format String currency in java -



Format String currency in java -

how can format pattern: r$123.456.789,12 this: 123456789.12?

what tried:

string valor_minimo = msessao.getstring("filtro_pedidos_valor").substring(2); string valor_maximo = msessao.getstring("filtro_pedidos_valor_maior").substring(2); decimalformat dec = new decimalformat("#.## eur"); dec.setminimumfractiondigits(2); string credits = dec.format(valor_maximo);

but does`t work.

this bit messy java rusty, believe you're looking .replace method. you're receiving illegalargumentexception because you're trying format string.

give try, , rework needed:

string number = "r$123.456.789,0"; number = number.replace(".", ""); number = number.replace(",", "."); //put sec previous line won't wipe out period number = number.replace("r", ""); number = number.replace("$", ""); //two ways can this. either create instance of decimalformat, or phone call anonymously. //instance call: decimalformat df = new decimalformat("#.##"); //now parse number , feed decimal formatter number = df.format(double.parsedouble(number)); //anonymous call: number = new decimalformat("#.##").format(double.parsedouble(number)); //output test: system.out.println(number);

hope helps!

edited more finish , robust answer.

java string formatting decimal string-formatting

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -