How do you round a double in Dart to a given degree of precision AFTER the decimal point?

前端 未结 12 1071
[愿得一人]
[愿得一人] 2020-12-08 03:46

Given a double, I want to round it to a given number of points of precision after the decimal point, similar to PHP\'s round() function.

The closest thing I

12条回答
  •  生来不讨喜
    2020-12-08 03:57

        var price=99.012334554;
    price = price.toStringAsFixed(2);
    print(price); // 99.01
    

    That is the ref of dart. ref: https://api.dartlang.org/stable/2.3.0/dart-core/num/toStringAsFixed.html

提交回复
热议问题