Reputation: 327
I prompt the user to input a variable 'year'.
I need to get the first 2 digits, and the last 2 digits of the 4-digit variable year for the Gaussian algorithm and store them in two separate variables.
What I need help on is getting the first 2 and last 2 numbers from 'year'.
Upvotes: 0
Views: 90
Reputation: 28991
To add to Bart's answer, if you're keeping it in string form you can just use sub
to grab the parts you want:
year = '1969'
firsttwo = year:sub(1,2)
secondtwo = year:sub(3,4)
Upvotes: 1
Reputation: 170178
Try this:
local n = 1234
local first = math.floor(n / 100)
local last = n % 100
print(first, last)
which print:
12 34
Upvotes: 1