I want to multiply a figure and then have it rounded to remove any decimal places but returned as a double, rather than an int since that is what I need.
I've tried this:
double number = 84.5; double coke = (number * 2.3).round()) as double;
double coke = double.parse(number * 2.3).round());
But I can't get it to be a double, it just throws errors. The value would be
194.35 in this case and I want it to be
Solution 1: CopsOnRoad
double number = 84.5; double answer = (number * 2.3).roundToDouble(); // 194.0
Solution 2: jamesdlin
double number = 84.5; double coke = (number * 2.3).round().toDouble();
as double doesn't work because
as changes what type the object is treated as but doesn't change the underlying object.