formatFractionDigitsAsFixed function

String formatFractionDigitsAsFixed(
  1. double amount, {
  2. int fractionDigits = 2,
  3. bool autoClearZero = false,
})

保留n位小数

Implementation

String formatFractionDigitsAsFixed(double amount,
    {int fractionDigits = 2, bool autoClearZero = false}) {
  String fixed = amount.toStringAsFixed(fractionDigits);
  if (autoClearZero) {
    fixed = fixed.replaceAll(".00", "");
  }
  return fixed;
}