flutter double 2 decimal places code example
Example 1: double variable into 2 decimal places flutter
double num1 = double.parse((12.3412).toStringAsFixed(2));
double num2 = double.parse((12.5668).toStringAsFixed(2));
double num3 = double.parse((-12.3412).toStringAsFixed(2));
double num4 = double.parse((-12.3456).toStringAsFixed(2));
Example 2: double 2 decimal places flutter
extension Ex on double {
double toPrecision(int n) => double.parse(toStringAsFixed(n));
}
void main() {
double d = 2.3456789;
double d1 = d.toPrecision(1);
double d2 = d.toPrecision(2);
double d3 = d.toPrecision(3);
}