123456789101112131415161718192021 |
- /// 数值工具类
- class NumUtil {
- NumUtil._();
- /// 对double四舍五入
- static double roundDouble(double value, [int digits = 2]) {
- final digitsStr = value.toStringAsFixed(digits);
- final result = double.parse(digitsStr);
- return result;
- }
- /// 在一定精度上几乎相等
- static bool almostEquals(
- double num1,
- double num2, [
- double precision = 0.000001,
- ]) {
- if (num1.isNaN && num2.isNaN) return true;
- return (num1 - num2).abs() <= precision;
- }
- }
|