Given a double, I want to round it to a given number of precision points after the decimal point, similar to the PHP round () function.
The closest thing I can find in Dart docs is double.toStringAsPrecision (), but thatβs not exactly what I need, because it includes digits to the decimal point in common precision points.
For example, using toStringAsPrecision (3):
0.123456789 rounds to 0.123 9.123456789 rounds to 9.12 98.123456789 rounds to 98.1 987.123456789 rounds to 987 9876.123456789 rounds to 9.88e+3
As the value of the number increases, I accordingly lose accuracy after the decimal point.
precision double-precision dart
Lucas meadows
source share