# Answers for "how to round up numbers in dart"

3

double variable into 2 decimal places flutter

``````double num1 = double.parse((12.3412).toStringAsFixed(2));
// 12.34

double num2 = double.parse((12.5668).toStringAsFixed(2));
// 12.57

double num3 = double.parse((-12.3412).toStringAsFixed(2));
// -12.34

double num4 = double.parse((-12.3456).toStringAsFixed(2));
// -12.35``````
Posted by: Guest on November-29-2020
2

dart round to 2 decimals

``````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``````
Posted by: Guest on September-14-2021
0

round off in dart

``````//dart code
double x = 5.56753;
String roundedX = x.toStringAsFixed(2);
print(roundedX);``````
Posted by: Guest on May-05-2021