formatNumber static method
Formats a number the PDF way: no exponent, no unnecessary trailing
zeros, and no .0 for integers.
Implementation
static String formatNumber(double value) {
if (!value.isFinite) return '0';
if (value == value.roundToDouble() && value.abs() < 1e15) {
return value.toInt().toString();
}
var text = value.toStringAsFixed(6);
if (text.contains('.')) {
text = text.replaceFirst(RegExp(r'0+$'), '');
if (text.endsWith('.')) text = text.substring(0, text.length - 1);
}
return text.isEmpty ? '0' : text;
}