Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i make a script print the last number of a value?

Asked by 5 years ago

what i would like is a script that would print the last number of a value

example: if my number was 15 it would print 5 ive tried to do this and it just wont work

0
string.sub(String, initivial value, value to cut) this cut a string, but 15 is a number, do you need to use tostring() this converts anything to a string, so it would be: String.sub(tostring(15), 2, 2) milkdelicious 1 — 5y
0
You don't need tostring() ^ DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years ago
Edited 5 years ago

The modulus opperator. % can be used for exactly what you need. Simply do local LastDigit = Number % 10 and you'll get the last digit of the number. In the case you want to remove decimals too, use math.floor(Number % 10) instead.

Ad

Answer this question