View Full Version : Placeholder zeros
SB3606
12-04-2004, 10:48 AM
Is there a way to have a variable as 01 rather than 1? I have it set to that, but whenever I do "unitnum = unitnum + 01;" it just gets rid of the zero. I need these for writing strings of values for a Play-by-Email game I'm making. (using AMS to make the army builder)
You could cheat and do something like this.
if String.Length(unitnum) == 1 then
unitnum = "0"..unitnum
end
The issue is that unitnum is a nurmeric variable, so the leading 0 is dropped. Once you combine the string variable "0" with it, it becomes a string, and the 0 leads as you want.
SB3606
12-04-2004, 12:28 PM
Thanks very much :lol
TJ_Tigger
12-04-2004, 02:52 PM
LUA has a string.format (all lowercase) that can do this as well.
num = 1
num = string.format("%02.f", num)
Label.SetText("Label1", num);
The % is an escape sequence, the zero is the padding, two for the number of characters and a decimal place holder followed by f for float.
Corey
12-04-2004, 03:04 PM
Nice one Tigg! :yes
TJ_Tigger
12-04-2004, 03:15 PM
Nice one Tigg! :yes
Thanks trying to lear a little from the Lua-users.org site
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.