currencyFormatWithSymbol method
通用货币格式化方法(带符号,输入单位为分)。
example:
15000.currencyFormatWithSymbol('¥'); // ¥150.00
15000.currencyFormatWithSymbol('\$', autoMoneyUnit: true); // \$150.00
Implementation
String currencyFormatWithSymbol(String symbol, {bool autoMoneyUnit = false}) {
if (this == null) {
return '${symbol}0.00';
}
final resultAmount = this! / 100;
String formatted;
if (autoMoneyUnit) {
formatted = _formatPrice(resultAmount);
} else {
formatted = resultAmount.toStringAsFixed(2);
}
// 中文(及通用货币)惯例:符号与数字之间不加空格(¥150 而非 ¥ 150)。
return '$symbol$formatted';
}