(x, opt_line_no, opt_line)
| 1094 | * @param {string=} opt_line The text of the line from which the string comes. |
| 1095 | */ |
| 1096 | export function parseFloat_(x, opt_line_no, opt_line) { |
| 1097 | var val = parseFloat(x); |
| 1098 | if (!isNaN(val)) return val; |
| 1099 | |
| 1100 | // Try to figure out what happeend. |
| 1101 | // If the value is the empty string, parse it as null. |
| 1102 | if (/^ *$/.test(x)) return null; |
| 1103 | |
| 1104 | // If it was actually "NaN", return it as NaN. |
| 1105 | if (/^ *nan *$/i.test(x)) return NaN; |
| 1106 | |
| 1107 | // Looks like a parsing error. |
| 1108 | var msg = "Unable to parse '" + x + "' as a number"; |
| 1109 | if (opt_line !== undefined && opt_line_no !== undefined) { |
| 1110 | msg += " on line " + (1+(opt_line_no||0)) + " ('" + opt_line + "') of CSV."; |
| 1111 | } |
| 1112 | console.error(msg); |
| 1113 | |
| 1114 | return null; |
| 1115 | } |
| 1116 | |
| 1117 | // Label constants for the labelsKMB and labelsKMG2 options. |
| 1118 | // (i.e. '100000' -> '100k') |
nothing calls this directly
no test coverage detected