How to parse an String to Integer with grouping, decimal separators ?

U

Ulf Meinhardt

As well known a decimal can be written with decimal separators. E.g

1,234,567.89 (US format)
1.234.567,89 (European format)

How can I parse a String which contains such a inetger number into an int variable.
The parse statement should work with the US AND the european decimal separators.

String mystr = "1.234.567,89";
int myint = Integer.parseInt(mystr);

does not work. It runs into an exception.

Ulf
 
J

J. David Boyd

As well known a decimal can be written with decimal separators. E.g

1,234,567.89 (US format)
1.234.567,89 (European format)

How can I parse a String which contains such a inetger number into an int
variable. The parse statement should work with the US AND the european
decimal separators.

String mystr = "1.234.567,89";
int myint = Integer.parseInt(mystr);

does not work. It runs into an exception.

Ulf

money isn't an Integer amount. Try a double, perhaps...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top