Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Neil Shweky
Neil Shweky
5,022 Points

Limiting integer to two numbers

Hi, I have a label in which I am printing an integer. I want to make it that no matter how many numbers you press only two numbers are printed, the last two inputted. Also the value of this number should be equal to what is printed. (Sort of like how you would input numbers into a timer...)

How do I do this?

Thanks!

1 Answer

I would convert the number to a string then substring it. only grabbing the last two numbers. After that, you can either leave it as a string, or convert it back to an integer..

Neil Shweky
Neil Shweky
5,022 Points

Wow! Great idea! I'll try it