I couldn't find a way to round double to 2 decimal places and remove trailing zeros in Dart. I found a way to round but it doesn't work if I try to truncate trailing zero.
Here is what I am trying to do:
double x = 5.0;
double y = 9.25843223423423;
double z = 10.10;
print(x); //Expected output --> 5
print(y); //Expected output --> 9.26
print(z); //Expected output --> 10.1
EDIT:
I found a way to solve the first 2 print statements above. I thought I should add it for whoever is searching it.
String getFormattedNumber( num ) {
var result;
if(num % 1 == 0) {
result = num.toInt();
} else {
result = num.toStringAsFixed(2);
}
return result.toString();
}