+1 vote

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

in Engine by (210 points)

2 Answers

+3 votes

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.

by (1,328 points)
0 votes

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.

by (148 points)

using int(3.765) will go faster than parsing strings

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.