How to do Integer division in Dart?

That is because Dart uses double to represent all numbers in dart2js. You can get interesting results, if you play with that:

Code:

int a = 1; 
a is int; 
a is double;

Result:

true
true

Actually, it is recommended to use type num when it comes to numbers, unless you have strong reasons to make it int (in for loop, for example). If you want to keep using int, use truncating division like this:

int a = 500;
int b = 250;
int c;

c = a ~/ b;

Otherwise, I would recommend to utilize num type.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)