Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to format an integer value with leading zeros

Author
Message
AquaGirl
11
Years of Service
User Offline
Joined: 6th Mar 2013
Location:
Posted: 13th Mar 2013 17:12
Hi

I don't know if it's possible using the ADK or not but I have a score as an integer that I want to format to a string with leading zeros i.e. 123 would become "0123".???


Katie

Katie
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 13th Mar 2013 17:46
There is a function for padding numbers in The Useful Community Functions pack

You can download it and other useful functions from http://forum.thegamecreators.com/?m=forum_view&t=193433&b=41
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Mar 2013 17:53 Edited at: 13th Mar 2013 17:54
alternatively you can add "0000000"+str(123) and cut what you need with right()
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 13th Mar 2013 18:01
I like Markus' idea. Never thought of that myself, quite an efficient way of doing this


Demo 3 is out now!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Mar 2013 19:01 Edited at: 13th Mar 2013 19:02

some languages have a String$("0",x) function.
then it would be look better like
v$=str(i)
score$=String$("0",8-len(v$))+v$
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Mar 2013 19:40
Quote: "some languages have a String$("0",x) function."

True, but AppGameKit doesn't.

Your first suggestion is a much more elegant one than the one I had done before (similar to the UCF one).

Now, in Tier 2, sprintf handles all my numeric formatting very nicely.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
AquaGirl
11
Years of Service
User Offline
Joined: 6th Mar 2013
Location:
Posted: 13th Mar 2013 19:53
Thanks guys, the Useful community functions pack did it for me!



Katie
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 13th Mar 2013 22:21
Quote: "alternatively you can add "0000000"+str(123) and cut what you need with right()"

which is
right( "0000000"+str(value) , length)
this can be also done with
right( str(1000000000 + value) , length)

dunno which is faster

Login to post a reply

Server time is: 2024-05-07 20:40:51
Your offset time is: 2024-05-07 20:40:51