Jump to content

tonumber and string.gsub


Jockie

Recommended Posts

http://www.lua.org/manual/5.1/manual.html#pdf-tonumber

You don't want to change the base parameter but string.gsub returns 2 values. One being the substring and the other the place (integer) at which the sub string starts. Both of these values are passed to your tonumber and it causes the error. Why? Because your base will be 1 (where $ is found), but you can't pass a value smaller than 2 and larger than 35.

If you expect $ to be anywhere else than at start then you want to assign the first returned value from string.gsub to a variable and pass it to tonumber later but if you expect the $ to be as the first character then you can use this method instead:

tonumber( string.sub( "$900", 2, -1 ) ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...