In Lua 5.2 or earlier, both tostring(10)
and tostring(10.0)
result as the string "10"
.
In Lua 5.3, this has changed:
print(tostring(10)) -- "10"
print(tostring(10.0)) -- "10.0"
That's because Lua 5.3 introduced the integer subtype. From Changes in the Language:
The conversion of a float to a string now adds a
.0
suffix to the result if it looks like an integer. (For instance, the float2.0
will be printed as2.0
, not as2
.) You should always use an explicit format when you need a specific format for numbers.
In Lua 5.2 or earlier, both tostring(10) and tostring(10.0) result as the string "10" . In Lua 5.3, this has changed: print(tostring(10)) -- "10" ...
In Lua, you can convert a number to a string using the tostring() function. 10 ...
Lua just does automatically conversion between strings and numbers. If you want ensure the type, use a = tonumber(a). – xpol. Feb 26, 2016 at 3:52.
Idiom #55 Convert integer to string · S : String := Integer'Image (I); · #include <stdlib.h>. char s[0x1000]={}; itoa(i,s,10); · (let [s (str i)]) · #include < ...
Strings have the usual meaning: a sequence of characters. ... We can specify a character in a string also by its numeric value through the escape sequence ...
Variables can store values of any data type ( number , string , boolean , and nil ). After a value is assigned, the variable can be updated to a new value as ...
20 – The String Library. The power of a raw Lua interpreter to manipulate strings is quite limited. A program can create string literals and concatenate ...