Remove currency symbol and text

88 views
Skip to first unread message

Antonio R. de Oliveira

unread,
Jun 6, 2012, 2:53:43 PM6/6/12
to google-we...@googlegroups.com
I want to remove symbols and text from formatted String when using NumberFormat.getCurrencyFormat().format() with internationalization.

Examples after remove:

Currency  - Formated  = Without 

US:        US$100.15  = 100.15
BRL:     100,15R$    = 100,15
Euro:    100,15€     =  100,15

Thanks.

Jens

unread,
Jun 6, 2012, 4:03:55 PM6/6/12
to google-we...@googlegroups.com
Couldn't you just parse the string using getCurrencyFormat().parse() to get a double value for it and then format it again using getDecimalFormat().format() ?

-- J.

Antonio R. de Oliveira

unread,
Jun 11, 2012, 12:58:59 PM6/11/12
to google-we...@googlegroups.com
Not, just need to format like previous examples.

Philippe Lhoste

unread,
Jun 21, 2012, 7:06:09 AM6/21/12
to Google-We...@googlegroups.com
On 06/06/2012 20:53, Antonio R. de Oliveira wrote:
> I want to remove symbols and text from formatted String when using
> /NumberFormat.getCurrencyFormat().format()/ with internationalization.
>
> Examples after remove:
>
> Currency - Formated = Without
>
> US: US$100.15 = 100.15
> BRL: 100,15R$ = 100,15
> Euro: 100,15� = 100,15

A possible solution:

String data = "US$100.15\n" +
"100,15R$\n" +
"100,15�\n";
String res = data.replaceAll("[^\n\\d,.]+", "");

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --



Reply all
Reply to author
Forward
0 new messages