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.


in Engine by (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.

by (1,567 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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.