반응형
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);
반응형
'개발하자' 카테고리의 다른 글
현재 IPython / Jupyter 노트북 이름을 얻으려면 어떻게 해야 합니까 (0) | 2023.03.13 |
---|---|
어떻게 하면 쿠버네티스에서 자바 애플리케이션에 할당된 힙 공간의 양을 우아하고 안전하게 최대화할 수 있을까요? (0) | 2023.03.13 |
AWS Cloud Formation - 속성 변경 무시 - Terraform 등가에서 'ignore_changes'? (0) | 2023.03.12 |
구글 콜랩 노트북 이름을 파이썬 변수에 할당할 수 있다. Jupyter에서는 javascript를 사용할 수 있지만 collab에서는 작동하지 않습니다 (0) | 2023.03.11 |
Python에서 중첩된 데이터 구조의 소수점 반올림 (0) | 2023.03.11 |