Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Finding a single digit

    Help
    2
    3
    194
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AndyG1985
      AndyG1985 last edited by

      I’m back, just noodling around and not committing to anything big :). Does anyone know if there’s a command to determine a single digit in a large number? e.g, the third number in 4567 would be 6. Also, for a single letter in a word? I’ve looked through all the help section in Fuze and I can’t find anything.

      1 Reply Last reply Reply Quote 0
      • PB____
        PB____ last edited by

        If you have a string, you can access a character in that string as an array (so using stringValue[index] notation, where index is zero based).
        You can also cast a number to a string, and then get a digit from that string with the same syntax.
        The following code snippet shows how you could apply this:

        function getDigit(number, digitIndex) // digitIndex is 0 based, so to get the third digit, it needs to be 2
            var numberAsString = str(number) // cast the number to a string, so you can access individual characters
            var digitAsString = numberAsString[digitIndex] // this is how you get a single letter in a word (to answer part of your question), in this case the word is a number as a string
            var digit = int(digitAsString) // it's possible to cast the digit back to a number (in case you want to do calculations with it)
        return digit // returning the digit as an int
        
        var value = getDigit(4567, 2) // returns 6, since that's the digit at zero based position 2
        print(value) // prints 6
        update()
        sleep(10)
        
        1 Reply Last reply Reply Quote 4
        • AndyG1985
          AndyG1985 last edited by

          Amazing, thanks a lot!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post