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.
Part of: How Clean works
The four core types — string, integer, number, boolean — each have conversion methods:
start:
string age_text = "28"
integer age = age_text.toInteger()
number score = 94.7
boolean passing = score >= 60.0
print("Age: " + age.toString())
print("Score: " + score.toString())
print("Passing: " + passing.toString())Age: 28
Score: 94.7
Passing: 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:
integer count = 5
number ratio = count.toNumber() / 2.0
print("Ratio: " + ratio.toString())
string price_str = "19.99"
number price = price_str.toNumber()
number with_tax = price * 1.1
print("Total: " + with_tax.toString())Ratio: 2.5
Total: 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.
- 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