Skip to content

Instantly share code, notes, and snippets.

@DmytroMitin
Last active August 29, 2015 14:27
Show Gist options
  • Save DmytroMitin/8e1fe8aa0a7406c508ae to your computer and use it in GitHub Desktop.
Save DmytroMitin/8e1fe8aa0a7406c508ae to your computer and use it in GitHub Desktop.
public class Doubles {
public Double parse(String s) {
if (isNumber(s)) {
return Double.valueOf(s);
} else {
return null;
}
}
public boolean isNumber(String s) {
try {
Double.valueOf(s);
if (s.charAt(s.length() - 1) == 'f' || s.charAt(s.length() - 1) == 'F' || s.charAt(s.length() - 1) == 'd' || s.charAt(s.length() - 1) == 'D') {
return false;
}
return true;
} catch (NumberFormatException e) {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment