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:
Tom Morris 2012-02-26 17:27:00 +00:00
parent 190e817fb8
commit c583ad4367

View File

@ -49,11 +49,17 @@ public class ToNumber implements Function {
if (args[0] instanceof Number) {
return args[0];
} else {
String s = args[0].toString();
try {
return Double.parseDouble(s);
} catch (NumberFormatException e) {
return new EvalError("Cannot parse to number");
String s = args[0].toString().trim();
if (s.length() > 0) {
try {
return Long.parseLong(s);
} catch (NumberFormatException e) {
}
try {
return Double.parseDouble(s);
} catch (NumberFormatException e) {
return new EvalError("Cannot parse to number");
}
}
}
}