Division of 2 by 4 returns 0(should be 0.5)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ceilingdoor
:warning: Old Version Published before Godot 3 was released.

That’s it. The following code:

print(2 / 4)

returns 0 but I believe it should return 0.5. My phone’s calculator returns 0.5 as well as the default Windows calculator. So, why does Godot output 0 instead of 0.5?

This standard C code returns the same than Godot:

 #include <stdio.h>

int main(void) {
	float r= 2/4;
	printf("%f", r);
	return 0;

Output is 0.000000

genete | 2016-03-31 22:20

:bust_in_silhouette: Reply From: Mohammad Hadi Aliakb


Also print(float(2)/4)

Bojidar Marinov | 2016-03-31 15:18

:bust_in_silhouette: Reply From: LittleRey

This is because 2 and 4 are implicit integers, so you need to use 2.0 or 4.0 to tell the script you want to compute float numbers