Factor out numeric sorting and handle trailing garbage better

More consistent number parsing, always using `%lf` and only truncating to integers later if needed.