Created
October 28, 2014 20:48
-
-
Save shiffman/548d528bfe0f60be3146 to your computer and use it in GitHub Desktop.
Parsing numbers with commas, what a pain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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