I’m parsing a file that has integer values using commas to separate thousands.
String s = "1,503"
Integer i = new Integer(s)
does not work, throws a parse exception. Is there an easy way to parse this?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
NumberFormatinstead. For example, in Java:(You can then get the integer value from the
Long, of course.)I’ve explicitly specified
Locale.USto guarantee that comma is used as the thousands separator; you may want to use a different locale if the input can vary.