What if your program could magically turn words into numbers and do math instantly?
Why String to number conversion in Kotlin? - Purpose & Use Cases
Imagine you receive a list of numbers as text from a friend, like "123", "456", and "789". You want to add them up, but they are all words, not real numbers.
Trying to add these text numbers directly will just join them like words, not add their values. Doing the math by hand or rewriting each as a number is slow and easy to mess up.
String to number conversion lets you turn those text numbers into real numbers quickly and safely, so you can do math with them just like normal numbers.
val sum = "123" + "456" // results in "123456"
val sum = "123".toInt() + "456".toInt() // results in 579
This lets you work with numbers that come as text from anywhere, like user input or files, and do real calculations with them.
When you build a calculator app, users type numbers as text. You convert those texts to numbers to add, subtract, or multiply them correctly.
Text that looks like numbers can't be used in math until converted.
Manual math on text is slow and error-prone.
String to number conversion makes math with text easy and reliable.