﻿ ThinBASIC Language > thinBasic Functions > String functions > Val
 Navigation:  ThinBASIC Language > thinBasic Functions > String functions > Val   Description

Return the numeric equivalent of a string argument.

Syntax

n = Val(StringExpression [, nDecimals])

Returns

Number

Parameters

 Name Type Optional Meaning StringExpression String No String expression to be converted into a number nDecimals Numeric yes Number of decimal places to return in the rounded number. If this optional parameter will be specified, returned value will be rounded the number of decimal places indicated.

Remarks

VAL can also be used to convert string arguments that are in the form of Hexadecimal, Binary and Octal numbers.

Hexadecimal values should be prefixed with "&H"

Binary values should be prefixed with "&B".

Octal values may be prefixed "&O", "&Q" or just "&".

If the StringExpression contains a leading zero, the result is returned as an unsigned value, otherwise, a signed value is returned.

Examples:

n = VAL("&HF5F3")       ' Hex, returns -2573 (signed)

n = VAL("&H0F5F3")      ' Hex, returns 62963 (unsigned)

n = VAL("&B0100101101"' Binary, returns 301 (unsigned)

n = VAL("&O4574514")    ' Octal, returns 1243468 (signed)

Restrictions

VAL stops analyzing StringExpression when non-numeric characters are encountered.

When dealing with Hexadecimal, Binary, and Octal number systems, the period character is classified as non-numeric.

VAL accepts the period character as a decimal place for all decimal number system values.

Examples