본문 바로가기

개발하자

flutter calculated double ~/ double but got int

반응형

flutter calculated double ~/ double but got int

setState(() {
  num result1 = double.parse(_speedTextEditingController.text) * double.parse(_weightTextEditingController.text) * 60;
  num result2 = double.parse(_medTextEditingController.text) * 1000 ~/ double.parse(_fluidTextEditingController.text);
  num result3 = double.parse(result1.toString()) ~/ double.parse(result2.toString());

  finalResult = result3.toString();
});

}

I'm a super newbie on programming. I started to code with flutter&dart.

I made 4 textControllers which i got result from each different textFields. Numbers from each textControllers are all in double. (Hope it to be...)

I inserted 4 numbers on each textField:

_speedTextEditingController => 15

_weightTextEditingController => 15

_medTextEditingController => 15

_fluidTextEditingController => 15

It must give me the finalResult as "13.5",

since (15*15*60) ~/ (15*1000~/15) = 13500 / 1000 = 13.5

But I only got "13" instead of "13.5"

Can anyone help me out from this problem?




~/ is used for integer division. Use / when you want to get a floating-point/decimal number.

Try this:

num result3 = double.parse(result1.toString()) / double.parse(result2.toString());
print(result3);

반응형