Why 6.0 and not 6? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why 6.0 and not 6?

Why is (4 + 8) / 2 6.0 instead of 6?

25th Dec 2019, 10:34 PM
KingQueen_Diya7
KingQueen_Diya7 - avatar
5 Answers
+ 6
It depends on programming language. In python the division outputs a float number whether it's operands are integer or float.
25th Dec 2019, 10:39 PM
Qasem
+ 3
Most probably is Python 3. You should use int((4 + 8) / 2)
25th Dec 2019, 10:41 PM
Mihai Apostol
Mihai Apostol - avatar
+ 2
Explicit conversion will make your life easier.
25th Dec 2019, 11:52 PM
Fernando Pozzetti
Fernando Pozzetti - avatar
+ 1
Because the output of this operation is double, not a int
25th Dec 2019, 10:46 PM
Ahmed Belkhodja
+ 1
In C, the result is actually 6.
26th Dec 2019, 12:49 AM
Gonçalo Magalhaes
Gonçalo Magalhaes - avatar