Types and Conversions
Clean Language is strictly typed — every variable has exactly one type and the compiler enforces it. Understanding the four core types and how to convert between them is the foundation for writing type-correct code.
The four core types — string, integer, number, boolean — each have conversion methods:
start:\n string age_text = "28"\n integer age = age_text.toInteger()\n number score = 94.7\n boolean passing = score >= 60.0\n\n print("Age: " + age.toString())\n print("Score: " + score.toString())\n print("Passing: " + passing.toString())Age: 28\nScore: 94.7\nPassing: trueEvery type has .toString() for concatenation. Use .toInteger() to convert a string to a whole number and .toNumber() to convert to a decimal. The compiler catches type mismatches — adding an integer to a string without converting first is a compile error, not a runtime surprise.
Convert between numeric types for mixed arithmetic:
start:\n integer count = 5\n number ratio = count.toNumber() / 2.0\n print("Ratio: " + ratio.toString())\n\n string price_str = "19.99"\n number price = price_str.toNumber()\n number with_tax = price * 1.1\n print("Total: " + with_tax.toString())Ratio: 2.5\nTotal: 21.989.toNumber() converts an integer to a decimal for arithmetic that produces fractions. .toInteger() converts in the other direction, truncating the decimal part. Always convert explicitly — Clean Language never coerces types silently.
Quick recap
- The four core types: string, integer, number, boolean
- Use .toString() to convert any type to a string for concatenation
- Use .toInteger() and .toNumber() to parse string values from user input
- The compiler prevents type mixing — conversion is always explicit