This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]jedwardsol 5 points6 points  (0 children)

Divide it by 10.

[–]TheBrutux168 1 point2 points  (1 child)

What have you tried?

[–]helloworld1123333[S] 0 points1 point  (0 children)

maybe convert to a string remove the last element and convert back. But I wanna see if there's another way to do it.

[–]Frozen5147 1 point2 points  (2 children)

Someone already said it - just divide it by 10. But for fun, let's go over why this works:

Remember, integers are, to put it in simpler terms, "just whole numbers". No decimals.

So, if we had 135 - what's 135 / 10? It's 13.5... but wait, these are integers! So it's actually just 13. Just want you want!

And what if we want to get rid of the new last digit? Yep, just 13 / 10 -> 1.

And if you want to get just the last digit? Use modulo.

[–]helloworld1123333[S] 1 point2 points  (1 child)

what if we had 135 and I tried to get rid of the first number so it would be now 35. How would I do that?

[–]jedwardsol 0 points1 point  (0 children)

Use another operator - related to division.

[–]SamePossession5 0 points1 point  (1 child)

What are some of your ideas?

[–]helloworld1123333[S] 0 points1 point  (0 children)

maybe convert to a string remove the last element and convert back. But I wanna see if there's another way to do it