Jump to content

Converting integer to string


Recommended Posts

Posted

Quick question. How can I convert an integer value to a string?

For example:

  
k = math.random(1,100) 
  

I want to convert k from an integer into a string. So if the value k is 41, then I want to convert it to "41".

Appreciated, thanks.

Posted

To add onto what KariiM said, tostring() converts anything into a string.

local plr = getPlayerFromName("Noki") 
tostring(isPedOnGround(plr)) 

will return either "true" or "false"

tostring(getPlayerFromName("Noki")) 

will return a string with the player element of a player named 'Noki'

tostring() converts anything into a string

However, tonumber() will either return a number (float or integer) or nil if invalid arguments were passed

tonumber(dxGetStatus()) 

will return nil as you cannot convert a table to an integer

tonumber("12") 

will return 12 as an integer

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