Separate whole number from floating integer?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 9BitStrider
:warning: Old Version Published before Godot 3 was released.

Let’s say my player value is 3.765. What formula would I use to separate the whole number from the decimal?

:bust_in_silhouette: Reply From: YeOldeDM

int(3.765) will return the integer 3.
You also have floor() (round down), ceil() (round up) and round() which rounds a value to the nearest integer.

:bust_in_silhouette: Reply From: gcivico

Hi 9BitStrider.

I am not an expert on GDScript but if you want to get the numbers on both sides of the point, maybe you can do this:

var playerValue = 3.765
var playerValueString = String(playerValue)
var playerValueParts = playerValueString.split(".")
print(playerValueParts[0], " - ", playerValueParts[1])
#	3 - 765

But if you only want to get the left part of the decimal the answer of YeOldeDM is the way.

using int(3.765) will go faster than parsing strings

phil1234 | 2021-05-21 18:48