java - Double.parseDouble() gives "Multiple Points, NumberFormatException" -
i have compare 2 strings parsing them double
.
strings are: "2.1.10" , "2.1.9". here, need know whether first 1 greater second 1 or not?
but, while parsing these using
double.parsedouble("2.1.10")
or double.parsedouble("2.1.9")
giving nullpointerexception saying "multiple points".
you don't compare doubles, compare version numbers, , not numbers, must compare each position.
something like:
string[] v1 = "2.1.9".split("\\."); string[] v2 = "2.1.10".split("\\."); if (v1.length != v2.length) return; (int pos = 0; pos < v1.length; pos++) { // compare v1[pos] v2[pos] necessary if (integer.parseint(v1[pos]) > integer.parseint(v2[pos])) { system.err.println("v1 greater"); } else if (integer.parseint(v1[pos]) < integer.parseint(v2[pos])) { system.err.println("v2 greater"); } }
result:
v2 greater
Comments
Post a Comment