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) { 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");
}
} }
} }
} }