How to use tonumber() (And why it is useful)

  • the built-in ROBLOX function tonumber(), simply translates what you give it to a number.
    What that means is, it takes what you give it (What you put in between the brackets) and turns it into a number.
    local var=tonumber("2")
    The value of var will be 2.
    so if we do,
    local var2=tonumber("2")+2
    then, the value of var2 will be four

  • @Void_Frost Its a Lua function ...

    It returns nil or the value representation of the string.

  • @kingdom5 How does that change what i said?
    It is still a built-in ROBLOX function, even if it is also in LUA.

  • @Void_Frost In your post you are stating its a Roblox-only function, when really its Roblox and Lua.

  • @Void_Frost It is like saying someone got a software from a company and letting people using it is their own company's software.

  • @Thundermaker300 I didnt say ROBLOX-only.

  • I'm going to read this eventually. LUA should be edited to look like Lua. Per the lua documentation they explain:


    I'm so sorry.

  • @kools Thanks for posting that quote & link; I've searched it before, but didn't know to look there.

    @Void_Frost You said "built-in ROBLOX function tonumber", which is misleading -- it's not Roblox's function, but a Lua function (you can use it in non-Roblox Lua just the same). "built-in Roblox function" makes it sound like the Roblox team built it into Roblox, which they didn't.

    Further, as kingdom5 indicated, you failed to explain when it returns nil, making your post incomplete.

  • Pssh, responses about the wording of ROBLOX functions ... I can be the most pedantic! Each and every one of you missed an entire optional argument to tonumber that is labelled in the lua reference manual.

    tonumber (e [, base])

    Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.
    An optional argument specifies the base to interpret the numeral. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. In base 10 (the default), the number can have a decimal part, as well as an optional exponent part (see §2.1). In other bases, only unsigned integers are accepted.

    For example I can use tonumber to interpret binary in the form of strings from the ROBLOX command bar.


    @Void_Frost I encourage you to edit your post (I think that's a functionality) to make sure your work is accurate and precise for everyone coming to read it.

  • @Void_Frost Let me rephrase; You stated it was ROBLOX, not Lua.

  • @kools It can't convert binary into decimal, though.

  • @kingdom5 how are you going to constantly bug him about it being lua too. Who Cares if it's lua. I script both. This is a tuturial section. Not a Lua tuturial section, not a binary tutorial section, A ROBLOX TUTURIAL SECTION. This post was meant for the not so experienced scripters for ROBLOX. you're not cool cause you know a couple things about lua. I know lua, Html, Binary, and roblox if you wanna count that. So stop tryig to find a fault in a post and go do something with your life.

  • @Thundermaker300 I never said it wasn't lua though. What i said was true. It's a built in ROBLOX function, even if it's also in lua.

Log in to reply
