currencyFormatWithDef method

String currencyFormatWithDef(
  1. bool autoMoneyUnit
)

金额格式化处理(输入单位为分)。

autoMoneyUnit 为 true 时按金额大小自动去尾零(整数无小数点、 .0/.x0 去尾零),否则恒定输出两位小数。

Implementation

String currencyFormatWithDef(bool autoMoneyUnit) {
  if (this == null) {
    return autoMoneyUnit ? '0' : '0.00';
  }
  final resultAmount = this! / 100;

  if (autoMoneyUnit) {
    return _formatPrice(resultAmount);
  }
  return resultAmount.toStringAsFixed(2);
}