Dart - round down a double
If you need to round down with certain precision - use this:
double roundDown(double value, int precision) {
final isNegative = value.isNegative;
final mod = pow(10.0, precision);
final roundDown = (((value.abs() * mod).floor()) / mod);
return isNegative ? -roundDown : roundDown;
}
roundDown(0.99, 1) => 0.9
roundDown(-0.19, 1) => -0.1
You can use both the Truncating division operator:
int hours = minutes ~/ 60;
Or the floor method:
int hours = (minutes/60).floor();