Why is "(1/6) * (66.900009-62.852596)" evaluated to zero?

It is executed both in Objective-C (Xcode) and in Python (terminal) and (1/6)*(66.900009-62.852596)is equal to zero. Does anyone know why this is? Shouldn't it be 0.26246?

+3
source share
3 answers

You do integer arithmetic on 1/6, and gender 1/6- 0. Try it instead 1.0/6.

+11
source

1/6is an integer division that becomes 0. Try to use instead 1.0/6.

+3
source

, from __future__ import division :

>>> from __future__ import division
>>> (1/6)*(66.900009-62.852596)
0.6745688333333331

, Python 3.

+2

All Articles