Where string is a character string literal, variable or expression.
Convert a character string to floating-point number.
Any valid floating-point value.
The string should contain characters representing a decimal number without any punctuation except for period (.), plus (+), minus (-), or “e” (scientific format). To convert a string representing a hexidecimal number, see DEC().
Any spaces (character $20 = CHR$(32)) are ignored. Conversion stops at the first invalid character. If no valid numeric characters were found, the returned value is zero. This is important, as some characters will appear as a space on screen but if they precede the numeric characters, VAL() will return zero! Particularly bad are the non-breaking-space and cursor-right characters ($A0 = CHR$(160) and $1D = CHR$(29), respectively) – these usually appears exactly like a space on-screen! Other leading white space (tabs, line feed, carriage return) will cause the same problem, although they usually are obviously the problem when printed on-screen.
PRINT VAL(" 12 3") 123 PRINT VAL(" 12,3") 12 PRINT VAL(" 12.3") 12.3 PRINT VAL("1BED") 1 PRINT VAL("BED") 0 PRINT VAL("") 0
This page is a member of Commodore BASIC