Convert a string into a number the hard way / Lua Scripting
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): https://www.youtube.com/watch?v=Ho10vCOYffM
Discord server: https://discord.gg/mxqM4hf Support me in paypal: https://www.paypal.com/paypalme/CodesOtakuYT
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬ ... https://www.youtube.com/watch?v=NoA7EpopHpM
59264524 Bytes