+ 1
Why do I have the wrong result for a simple double calculation?
I calculated 2000/4000 and get 0. https://code.sololearn.com/cChdU45Yrso1/?ref=app
5 ответов
+ 2
You divide 2 ints, store them as double
+ 1
The program is doing integer division and then storing the result into a double precision float. It is doing integer division because both operands are integer. If you make either one into floating point then the result will be kept in floating point.
0
1337element did you mean
2000 / 4000 = 0
or
4000 / 2000 = 2
0
Oh yeah thanks I thought it is fine when result is double. Thanks.
0
1337element result is fine as a double as 2.0 if 4000/2000
the int/int later simply left it as int 2