decodeDoubles method
Decode all fields as doubles.
Throws CsvParseException (with row and column) for any field that
is not a valid double. Empty fields throw too, unless emptyAs
provides an explicit fill value.
Implementation
List<List<double>> decodeDoubles(
String input,
CsvConfig config, {
double? emptyAs,
}) {
final stringRows = decodeStrings(input, config);
final result = <List<double>>[];
for (var r = 0; r < stringRows.length; r++) {
final row = stringRows[r];
final out = <double>[];
for (var c = 0; c < row.length; c++) {
final s = row[c];
if (s.isEmpty) {
if (emptyAs == null) {
throw CsvParseException(
'Empty field is not a valid double '
'(pass emptyAs to fill empty fields)',
row: r,
column: c,
);
}
out.add(emptyAs);
} else {
final v = double.tryParse(s);
if (v == null) {
throw CsvParseException(
'Field "$s" is not a valid double',
row: r,
column: c,
);
}
out.add(v);
}
}
result.add(out);
}
return result;
}