|
String and Number ConversionWhen performing an assignment to a variable, you can convert a value from a string to a number, or vice versa. The following are examples of assignments in which a string is converted to an integer and to a floating point number:
Here, integertemp is assigned the number 37, and floattemp is assigned the number 98.6. The actual conversion is performed by two predefined chunks of code known as functions: int converts a string to an integer, and float converts an integer to a string.
The function str converts a number to a string:
Functions are discussed in more detail in the Functions section. |