Parsing and Converting Numbers
Turn strings into numbers and back.
Text Is Not a Number
User input and files arrive as strings. The text "42" cannot do math until you parse it into a real number first. 🔄
Parse to an int
Call int.parse to turn a digit string into an int. The result is a true number you can add, compare, or store.
void main() {
int n = int.parse('42');
print(n + 1); // 43
}All lessons in this course
- Arithmetic and Operator Precedence
- int vs double and Integer Division
- Parsing and Converting Numbers
- The dart:math Toolkit