converting .123456 to 123456

ultimaultima 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

  • AlkaPPAlkaPP Member, PRO Posts: 194

    @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.

  • ultimaultima Member, PRO Posts: 1,207

    yes this only works for integers not decimals

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

  • ultimaultima Member, PRO Posts: 1,207

    this worked beautifully thank you so much.

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

    @tatiang -- That is a really nice solution!

Sign In or Register to comment.