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

 

To round a double in Dart to a given degree of precision AFTER the decimal point, you can use the built-in solution in dart toStringAsFixed() method, but you have to convert it back to double


void main() {

   var a = 11.23984948449;

 print(a.toStringAsPrecision(3));     // result are : 11.2

 print((4321.12345678).toStringAsFixed(3));  // result are : 4321.123

 print(a.toStringAsFixed(3));    // result are : 11.240

 print(a.toStringAsExponential(3));    // result are : 1.124e+1

  }

Post a Comment

Thank you

Previous Post Next Post