1 / 10 = 0 ,but why not 0.1?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Godot_Starter

If you make this:

func _ready():
    var x = 1/10
    print(x)
    

It prints 0, but it must be 0.1

Why and how can I fix that?

:bust_in_silhouette: Reply From: Schweini

As GDScript is a dynamic language, I assume Godot assigned x as an integer.

If you want x to be 0.1 you have to write var x : float = 1/10, this is static typing.

For more information: Static typing in GDScript — Godot Engine (stable) documentation in English

:bust_in_silhouette: Reply From: klaas

HI,
because 1 and 10 are integer and not floating point.
Try 1.0 / 10.0 this should do the trick.