Is there a native way (preferably without implementing your own method) to check that a string is parseable with Double.parseDouble()?
Is there a native way (preferably without implementing your own method) to check that
Share
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.
The common approach would be to check it with a regular expression like it’s also suggested inside the
Double.valueOf(String)documentation.The regexp provided there (or included below) should cover all valid floating point cases, so you don’t need to fiddle with it, since you will eventually miss out on some of the finer points.
If you don’t want to do that,
try catchis still an option.The regexp suggested by the JavaDoc is included below: