Skip to content

Instantly share code, notes, and snippets.

@shiffman
Created October 28, 2014 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiffman/548d528bfe0f60be3146 to your computer and use it in GitHub Desktop.
Save shiffman/548d528bfe0f60be3146 to your computer and use it in GitHub Desktop.
Parsing numbers with commas, what a pain
import java.text.NumberFormat;
String s = "256,128";
int val = int(s.replaceAll(",",""));
println(val);
int val2 = 0;
NumberFormat nf = NumberFormat.getNumberInstance(java.util.Locale.US);
try {
val2 = nf.parse(s).intValue();
}
catch (Exception e) {
println("oops");
}
println(val2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment