# converting .123456 to 123456

Member, PRO Posts: 1,207

converting say .123456 to 123456

Hi guys, does anyone have a solution for this? (if you don't know how many digits there are)

I tried to use a loop until function and multiply the number by 10 and checking if number - padint(number) is = 0

this solution gave me a weird number like 1234559999998

• Member, PRO Posts: 194

@ultima have you seen this thread?

I think it’s easier to count how many digits your number has first then use rule to x10, 100, 1000 etc regarding the digit count.

My Gamesalad Games On App Store:

• Member, PRO Posts: 1,207

yes this only works for integers not decimals

• Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,925
edited April 2019

Hmm, I thought you could do it with textReplace( ) or textSubStr( ) but it appears not to work, at least not with decimals.

So mathematically:

Change Attribute game.number to game.number*pow(10,textLength(game.number)-2)

By way of explanation, we're taking the length of the number you need -- which GameSalad reports back as two longer than it needs to be since it has a leading zero and decimal point -- and using it as a power of ten to multiply by the original number.

So for example, 0.123456 has a length of 8 so we multiply 0.123456 by 10^6 which gives us 123456.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Member, PRO Posts: 1,207

this worked beautifully thank you so much.

• Member, Sous Chef, PRO Posts: 2,859

@tatiang -- That is a really nice solution!