Dart Round To 2 Decimals

[Solved] Dart Round To 2 Decimals | Dart - Code Explorer | yomemimo.com
Question : dart round to 2 decimals

Answered by : jacob-j-van-wyk

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

Source : https://www.bezkoder.com/dart-round-double/ | Last Update : Tue, 21 Sep 21

Question : Round double to int flutter

Answered by : theo-kramer

int roundToInt(double meinDouble) { double multiplier = .5; return (multiplier * meinDouble).round();
}

Source : https://stackoverflow.com/questions/20788320/how-to-convert-a-double-to-an-int-in-dart | Last Update : Sun, 21 Aug 22

Answers related to dart round to 2 decimals

Code Explorer Popular Question For Dart