Operaciones aritméticas en el motor Godot

Godot Version

v4.2.2

Question

Excuse my ignorance I am new to this programming thing, I am trying Godot engine for the first time, I tried to do a simple operation and I expected 37.5 and I got 50, I have been trying for 1 hour without understanding why, maybe someone can help me with this, Thanks in advance for your help.

extends Node
func _ready():
var vida_final = 100-(250/100)*25
print(vida_final)

This is caused by integer arithmetic.
You are dividing integers and the division gets truncated: 250/100=2
Try 250.0/100 instead to use float number arithmetic.

1 Like

Thank you very much for your help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.