Question

So i have this number 1234567890 declared as this.

local num = 1234567890; 

and now i what to add those numbers together 2+4+6+8+0 so would i go about this?

Était-ce utile?

La solution

Try this:

local num = 1234567890
local sum = 0
for a,b in tostring(num):gmatch("(.)(.)") do
    sum=sum+tonumber(b)
end
print(sum)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top