Round up decimal and add to array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalala

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

:bust_in_silhouette: Reply From: kidscancode

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 @GDScript — Godot Engine (latest) documentation in English for details.

:bust_in_silhouette: Reply From: wombatstampede

This should work. But is untested:

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


:bust_in_silhouette: Reply From: aliu11

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

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

Rafiz | 2020-02-26 12:58