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 = []

Or, all together:


See https://docs.godotengine.org/en/latest/classes/[email protected] for details.

by (21,940 points)
0 votes

This should work. But is untested:

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


by (3,352 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 Frequently asked questions and 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 [email protected] with your username.