converting .123456 to 123456
ultima
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
Comments
@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:
Greedy Chubby: https://itunes.apple.com/us/app/greedy-chubby/id834371213?ls=1
yes this only works for integers not decimals
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
this worked beautifully thank you so much.
@tatiang -- That is a really nice solution!