Jump to content

tonumber()


Recommended Posts

Posted

Hey guys,

small question I'm using a tonumber() on a string which contains a number between 0 and 1 (example. 0.48)

Is it possible that it makes it 0 and not 0.48 becuase I'm getting an error that I'm compairing nil to a number which tonumber's return being the nil. I've output the string and gave me the number, without tonumber() I get trying to compaire string with number.

Kind regards,

Billy

Posted

LUA:

    outputServerLog(regenmmPerUur) 
    if (regenmmPerUur < 1) then 

Console:

[12:32:06] 0.252 
[12:32:06] ERROR: xml\server.lua:13: attempt to compare string with number 

When tonumber() is added, Console:

[12:34:13] ERROR: xml\server.lua:14: attempt to compare string with number 

Posted

Yes. BTW, it is normal that it confuses people, since they cannot know whether tonumber(..)'s arguments are passed by reference or value.

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