addPercent static method

String addPercent(
  1. String? num, {
  2. bool needOperate = false,
})

增加百分号,并加上正负符号 needOperate 是否需要加上正负号,默认不需要

Implementation

static String addPercent(String? num, {bool needOperate = false}) {
  if (num == null || num.isEmpty) return '+0.00%';
  if (isPositive(num) && needOperate) {
    return '+${(double.parse(num) * 100).toStringAsFixed(2)}%';
  } else {
    return '${(double.parse(num) * 100).toStringAsFixed(2)}%';
  }
}