Issue 537 - Try to convert to Long first before converting to Double. Matches behavior on import.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2446 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
190e817fb8
commit
c583ad4367
@ -49,11 +49,17 @@ public class ToNumber implements Function {
|
|||||||
if (args[0] instanceof Number) {
|
if (args[0] instanceof Number) {
|
||||||
return args[0];
|
return args[0];
|
||||||
} else {
|
} else {
|
||||||
String s = args[0].toString();
|
String s = args[0].toString().trim();
|
||||||
try {
|
if (s.length() > 0) {
|
||||||
return Double.parseDouble(s);
|
try {
|
||||||
} catch (NumberFormatException e) {
|
return Long.parseLong(s);
|
||||||
return new EvalError("Cannot parse to number");
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(s);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return new EvalError("Cannot parse to number");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user