![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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
![]() |
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 = []
a.append(x)
Or, all together:
a.append(int(ceil(x)))
See @GDScript — Godot Engine (latest) documentation in English for details.
![]() |
Reply From: | wombatstampede |
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]))
![]() |
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