Try this:
local num = 1234567890
local sum = 0
for a,b in tostring(num):gmatch("(.)(.)") do
sum=sum+tonumber(b)
end
print(sum)
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?
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)