format static method

num format(
  1. double? value,
  2. {int fractionDigits = 0}
)

将数字按格式输出

value数值

The parameter fractionDigits must be an integer satisfying: 0 <= fractionDigits <= 20.

Examples:

NumUtil.formatStr(0, fractionDigits: 3);  //0.0
NumUtil.formatStr(4321.12345678, fractionDigits: 3);  //4321.123
NumUtil.formatStr(4321.12345678, fractionDigits: 5);  //4321.12346
NumUtil.formatStr(123456789012345, fractionDigits: 3);  //123456789012345.0
NumUtil.formatStr(5.25, fractionDigits: 0); //5

Implementation

static num format(double? value, {int fractionDigits = 0}) {
  String valueStr = formatStr(value, fractionDigits: fractionDigits);
  return fractionDigits == 0 ? int.parse(valueStr) : double.parse(valueStr);
}