Dart/Flutter – How to convert one dataType to other Data

Posted by

Int to dubble

To convert a int to double in Dart, we can use one of the built-in methods depending on your need:

void main() {
  int i = 5;
  print(i.toDouble());          // 5.0
}

toInt( ) or truncate( ):

void main() {
  dubble i = 5.0;
  print(i.toInt());           // 5
 
}

round( ):

return the closest/nearest integer.

void main() {
int i = 4.7;
print(i.round()); // 5.0
}

ceil( ):

return the least integer that is not smaller than this number.

void main() {
  int i = 5.3;
  print(i.ceil());          // 5.0
}

floor( ):

return the greatest integer not greater than this number

void main() {
  int i = 5.3;
   print(i.floor());          // 5
 
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x