rowAmount function
Resolves a numeric field or multiplication expression against row.
Implementation
double rowAmount(dynamic row, String expression) {
if (row is! Map) return 0;
try {
final result = evaluateFormula(expression, row);
if (result is num) return result.toDouble();
final match = RegExp(r'-?[0-9]+([.,][0-9]+)?').firstMatch('$result');
if (match == null) return 0.0;
var str = match.group(0)!;
final lastDot = str.lastIndexOf('.');
final lastComma = str.lastIndexOf(',');
if (lastComma > lastDot) {
str = str.replaceAll('.', '').replaceAll(',', '.');
} else if (lastDot > lastComma) {
str = str.replaceAll(',', '');
} else {
str = str.replaceAll(',', '.');
}
return double.tryParse(str) ?? 0.0;
} catch (_) {
return 0;
}
}