# GameSalad

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# converting .123456 to 123456

Posts: 1,207Member, PRO

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

## Comments

• Posts: 194Member, PRO

@ultima have you seen this thread?

https://forums.gamesalad.com/discussion/60487/get-count-of-digits-in-a-number-how-to

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:

• Posts: 1,207Member, PRO

yes this only works for integers not decimals

• Posts: 11,907Member, Sous Chef, PRO, Senior Sous-Chef
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

• Posts: 1,207Member, PRO

this worked beautifully thank you so much.

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

@tatiang -- That is a really nice solution!

Sign In or Register to comment.