7.5 Type Conversion

In most cases you can safely rely on Cows' automatic type conversion. However, there are situations where you must force a conversion to obtain the right result. As an example, when you multiply a string by an integer n the result is the string repeated n times ("pamela" * 3 is "pamelapamelapamela"). For the same reason, "4" * 3 gives the string "444" as a result. So, if a variable stores the string "4" and you want a standard multiplication of two integers, you need a conversion:

x = 4;
print (x * 3);  // display 444
print (toint (x) * 3);  // display 12


Please note that the original variable is left unchanged: toint (x) is an integer but x is still a string. In the same spirit y = toint (x) will create the integer variable y but x will still be a string.

7.5.1 toint (expr)

7.5.2 tostring (expr)

7.5.3 toarray (expr)

This manual can be downloaded from http://www.g-cows.org/.