0 votes

This is Godot 3.

I'm doing some float work, and it kept coming back as an integer rounded down.


Returns 0

print (float(4/3) == float(1.0))

Returns True

print("%1.1f" % (18/10))

Returns 1.0

print("%1.1f" % 1.8)

Returns 1.8

Curious as to what I'm doing wrong or how to work around this issue.


asked Jun 9, 2018 in Engine by _themuffinman_ (12 points)

1 Answer

+1 vote

Try 1.0/2 or float(1)/2.

Division using only ints will return an int. If one of them is a float, the result will be a float.

answered Jun 9, 2018 by Diet Estus (1,504 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.