to_number("101", 2) = 5
to_number("101", 10) = 101
The custom function we made today support only whole positive (or null) numbers for now. Since it's the easiest to implement
Stay tunned for the next video were we're gonna support fractional numbers and negative numbers!
Lua does have a tonumber method, which is of course much more faster and convenient than our implementation. But doing stuff the hard way teach you a lot and helps you be grateful of such simple functions XD
Btw programmers in the early days had to do this every time themselves, Nowadays you don't need to implement it yourself unless again you want a custom behavior, like inventing your own number system or ignoring some characters since for example:
tonumber(" 1001 3234") will throw an error because there is a space in there
But keep in mind that there is unlimited amount of solutions for the same problem. that's just my solution, you can come up with your own or even your own numbers :D
Related video(s):
• string.byte and string.char Lua scrip...
Discord server:
/ discord
Support me in paypal:
https://www.paypal.com/paypalme/Codes...
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
Смотрите видео Convert a string into a number the hard way / Lua Scripting онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Codotaku 01 Январь 1970. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 647 раз и оно понравилось 13 посетителям.