# Conversion functions

When necessary, nuBASIC converts a numeric constant from one type of variable to another, according to the following rules:

If a numeric constant of one type is set equal to a numeric variable of a different type, the number is stored as the type declared in the variable name.

Example:

N% = 3.5

Print N%

Output:

3

• If a string variable is set equal to a numeric value or vice versa, a "Type Mismatch" error occurs.

• During an expression evaluation, all of the operands in an arithmetic or relational operation are converted to the same degree of precision; that is, that of the most precise operand. Also, the result of an arithmetic operation is returned to this degree of precision.

• Logical operators convert their operands to integers and return an integer result.

A string value can be converted in a numeric value and vice versa.

To convert a numeric value into a string value you may use Str\$ built-in function

To convert a string value you may use Val or Val% functions.

The second one converts directly the result into integer value instead of floating point value (as VAL does).

Examples:

Print Val("123")

123.000000

Print Val%("123")

123

Print Str\$(123)+ " is a number"

123 is a number