📅  最后修改于: 2022-03-11 14:48:04.144000             🧑  作者: Mango
import 'dart:math';
double roundDouble(double value, int places){
double mod = pow(10.0, places);
return ((value * mod).round().toDouble() / mod);
}
main() {
double num1 = roundDouble(12.3412, 2);
// 12.34
double num2 = roundDouble(12.5668, 2);
// 12.57
double num3 = roundDouble(-12.3412, 2);
// -12.34
double num4 = roundDouble(-12.3456, 2);
// -12.35
}
OR
double num1 = double.parse((12.3412).toStringAsFixed(2));
// 12.34