autoUnitFormat property
String
get
autoUnitFormat
单位自动转换(万 / 亿)。null 返回 '0'。
example:
123456789.autoUnitFormat; // "1.23亿"
15000.autoUnitFormat; // "1.50万"
Implementation
String get autoUnitFormat {
final self = this;
if (self == null) return '0';
final value = self.toDouble();
if (value >= 1e8) {
return '${(value / 1e8).toStringAsFixed(2)}亿';
} else if (value >= 1e4) {
return '${(value / 1e4).toStringAsFixed(2)}万';
} else {
return value.toInt().toString();
}
}