Integer division in Dart - type 'double' is not a subtype of type 'int'

前端 未结 3 1178
孤街浪徒
孤街浪徒 2020-12-16 09:54

I have trouble with integer division in Dart as it gives me error: \'Breaking on exception: type \'double\' is not a subtype of type \'int\' of \'c\'.\'

Her

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 10:09

    Integer division is

    c = a ~/ b;
    

    you could also use

    c = (a / b).floor();
    c = (a / b).ceil();
    

    if you want to define how fractions should be handled.

提交回复
热议问题