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 / Formatting numbers to include commas

Author
Message
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 12th May 2015 16:15
Working hard on my platform game! I want the score to use commas to group digits like 5,276,250. Preferably without leading zeros (ie not 005,267,250).

I started last night but scrapped what I'd done because it felt long winded (read rubbish) and given that the function will be called very regularly I want to get it efficient.

Any pointers as to how I might efficiently translate an integer eg 5276250 into the comma version string (ie 5,276,250) that I can use as text? Clearly the score will start at zero and gradually become 3...4..5..6..7..8.. digits long.

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th May 2015 16:39 Edited at: 12th May 2015 16:42

EDIT: Added a check that was missing

Using AppGameKit V2 Tier 1
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th May 2015 16:44 Edited at: 12th May 2015 16:50
something like this, but it is with zeros.
s=right( "0000000" + str(integer) ,7)
score = mid(s,1,1) + "," + mid(s,2,3)+ "," +mid(s,5,3)

AGK 108 (B)19 + AppGameKit V2 Beta .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 12th May 2015 18:43
OK...so you guys are much cleverer than me.... I'm still working out how yours works Baxslash! Really appreciate the input guys. Looking forward to posting the next progress video - it's moved on quite a bit...and now I can have a sensible score too!

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th May 2015 19:58
It just loops through the original number as characters rebuilding the string from right to left and every three characters adds a comma. Not as complicated as it seems really

Using AppGameKit V2 Tier 1
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 12th May 2015 20:42
Ah, cool. Yes good approach.

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
lmr2013
11
Years of Service
User Offline
Joined: 15th Jul 2013
Location:
Posted: 12th May 2015 21:12
already answered, this is what i currently use

DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 12th May 2015 22:03
That looks kind of nifty too!

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 13th May 2015 11:03
The question is, which one is the fastest?

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th May 2015 20:05 Edited at: 13th May 2015 20:08
lmr2013's version runs about 0.000002ms faster here:
mine = 0.000008ms
lmr2013's = 0.000006ms

I ran 100,000 of each and this was the average here.

EDIT not 10,000 it was 100,000

EDIT 2, that might be seconds not ms too in need of a beer to check

EDIT 3, who keeps adding badges to my profile... I deleted them all for a reason!!

Using AppGameKit V2 Tier 1
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 14th May 2015 10:30
Cheers baxslash. Yes I did some tests and lmr2013's was fractionally faster, though surprising how much each test varies I guess its things going on in the background on the computer. Sorry should have posted.

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)

Login to post a reply

Server time is: 2024-11-25 21:33:12
Your offset time is: 2024-11-25 21:33:12