User Tools

Site Tools


ugbasic:user:kw:val
Translations of this page:


ugBASIC User Manual

VAL ✓

SYNTAX

   = VAL(string)

PURPOSE

The VAL command is a function that allows you to convert a string that represents a number into a integer numeric value. In other words, it takes a string that contains numbers and returns the corresponding numeric value.

The VAL command is very useful when working with user input, because the user often enters numbers as strings. For example, if we ask the user to enter their age, the input will be a string. In order to perform calculations with this age, we must first convert it to a number.

The VAL function reads the string from left to right and stops at the first character that is not a number. The VAL function ignores spaces at the beginning of the string. If the string does not begin with a number or contains only non-numeric characters, the VAL function returns zero.

EXAMPLE

  PRINT VAL("123")

See also the following example files:

ABBREVIATION

 Va

AVAILABLE ON

SEE ALSO

STR

ANY PROBLEM?

If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!

POWERED BY