Always Round Number to 10ths - Even when whole? (1.0 / 2.0 / etc...)

Hoping this is an easy one, but I can’t find a solution: As the title says, I’m trying to have my text label show the tenths position consistently. I’m using a timer (stopwatch actually) that shows tenths of a second, and using math.floor:

					while player.ParkStatus.Value == "RunningDownhill02" and GUI.CurrentRunTime.Value < 60.1 do
						GUI.CurrentRunTime.Value = GUI.CurrentRunTime.Value + .1
						GUI.ImageLabel.TextLabel.Text =  math.floor(GUI.CurrentRunTime.Value * 10) / 10
						wait(.1)
					end

The result works for all but the whole seconds, because it doesn’t show the zero:

You could just check if the number is whole and then add .0 on the end.

if math.floor(number) == number then
     number = number..".0"
end
1 Like

You can use string.format to achieve this easily, for example:

string.format("%0.1f", 2) -- returns 2.0

You can also change the amount of decimal points to be returned:

string.format("%0.2f", 2) -- returns 2.00
string.format("%0.3f", 2) -- returns 2.000
2 Likes

Yet another example of how epic this community is. Perfect solution in moments. Joritochip, your concatenate solution would likely work also, but the string.format is perfect for me. This works flawlessly:

GUI.ImageLabel.TextLabel.Text = string.format("%0.1f",math.floor(GUI.CurrentRunTime.Value * 10) / 10,2)

THANK YOU to you both. 10.0 out of 10.0.

1 Like