Pregunta

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?

¿Fue útil?

Solución

Try this:

local num = 1234567890
local sum = 0
for a,b in tostring(num):gmatch("(.)(.)") do
    sum=sum+tonumber(b)
end
print(sum)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top