12.3.1 How it works
PseudoLearn never converts on its own. When needed, you ask:
| Function | Converts |
|---|---|
toText(v) | any primitive to String, with the same format as Write |
toInteger(t) | a decimal string to Integer |
toReal(t) | a decimal string to Real |
decimals(x, n) | a number to text with exactly n decimals |
At the top, the text "42" becomes a number with toInteger and comes back with toText. Below, the text "doce" cannot be converted and toInteger fails.
ProgramConverting both ways
Algorithm Conversiones
Write toText(12) + "!", " ", toInteger("42") + 1, " ", toReal("2.5") * 2;
Write decimals(3.14159, 2), " ", decimals(2.5, 0), " ", decimals(-0.001, 1);
EndAlgorithmOutput
12! 43 5.0 3.14 3 -0.0
The program finishes normally.
decimals rounds ties away from zero, keeps the sign —that is why -0.001 with one decimal is -0.0— and uses no thousands separators.
In short
- Every conversion is explicit.
toText,toIntegerandtoRealgo between text and numbers.- A text that is not a number fails; it does not become zero.
decimalsfixes a number's decimals.