0 votes

I am trying to round up float into int.
So 0.01-> 1 and .99->1. What method to use?
And how to add it to array

in Engine by (12 points)

3 Answers

+1 vote

Round up:

var x = 0.01
x = ceil(x)  # x is now 1.0

Change to int:

x = int(x)

Add to array:

var a = []
a.append(x)

Or, all together:

a.append(int(ceil(x)))

See https://docs.godotengine.org/en/latest/classes/class_@gdscript.html for details.

by (20,893 points)
0 votes

This should work. But is untested:

var fl1=0.01
var fl2=0.99
var arr = []

arr.append(int(ceil(fl1)))
arr.append(int(ceil(fl2)))

print(str(arr[0]))
print(str(arr[1]))
by (3,278 points)
0 votes

you can do
int(ceil(decimal number)) or
int(floor(decimal number + 1 ))

How to add number to array
var arrayname : Array //initize an array

arrayname.append(number)//add number to array
by (18 points)

wouldn't second option return 3 if input was 2.0?

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.