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

ultimaultima 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

  • AlkaPPAlkaPP 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:

    Greedy Chubby: https://itunes.apple.com/us/app/greedy-chubby/id834371213?ls=1

  • ultimaultima Posts: 1,207Member, PRO

    yes this only works for integers not decimals

  • tatiangtatiang Posts: 11,696Member, Sous Chef, PRO, Senior Sous-Chef
    edited April 11

    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

  • ultimaultima Posts: 1,207Member, PRO

    this worked beautifully thank you so much.

  • RThurmanRThurman Posts: 2,818Member, Sous Chef, PRO

    @tatiang -- That is a really nice solution!

Sign In or Register to comment.