Skip to main content

Flutter Dart Convert Double to Int

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

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:
toInt() function example in Dart
2. round() : Round function will return round number closest to integer value.
void main() {
  double a = 3.654;
  
  int b = a.round();
  
  // Also Can Use.
  var c = a.round();
  
  print(a);
  
  print(b);
  
  print(c);

}
Output:
Round number example in dart

Comments