To convert Double value into Integer value without throwing there are 2 easy ways. When we convert Double type value in Int then it will store before point value as integer value.
Flutter Dart Convert Double to Int
1. toInt() : To Integer function converts double number into integer number. See the code example for easy understanding.
void main() {
double a = 3.654;
int b = a.toInt();
// Also Can Use.
var c = a.toInt();
print(a);
print(b);
print(c);
}
Output:
void main() {
double a = 3.654;
int b = a.round();
// Also Can Use.
var c = a.round();
print(a);
print(b);
print(c);
}
Output:
Comments
Post a Comment