String function VAL

20  VAL (s)
Returns the numeric value of string s.

See examples

If there is insufficient information on this page and you wish learn more about VAL, please send an email to You can help to improve information about VAL by submitting an article using the comments link below. Note, an offline language reference text file is now avialable – see the Download section.


Here is an opportunity for enhancing SmallBASIC's function VAL, this EVAL is only beginning of what might be done.

' VAL test.bas  SmallBASIC 0.12.2 [B+=MGA] 2016-04-05
? val(s1)
? eval(s1)
func eval(numericexpressionstring)
  'working left to right, no parenthesis
  for i=1 to len(numericexpressionstring)
    if instr("0123456789.",c) then ds=ds+c
    if instr("+-*/",c) or i=len(numericexpressionstring) then
      'execute last cmd if one
      if cmd<>""  then
        select case cmd
        case "+":e=e+d
        case "-":e=e-d
        case "*":e=e*d
        case "/":e=e/d
        end select
      end if
      if i<>len(numericexpressionstring) then cmd=c
    end if
  'eval=str(e) '<=== I am setting up something for Turtle strings
  eval=e        '<=== normal people and usage might want this

Math EVAL function = evaluates a string as though it were an expression and returns a result.

I've written in Euphoria 4 correct math EVAL function, you can download it and see how it works, if you're really into it:*

It is straightforward to translate that Euphoria code into SmallBASIC code.

EVAL must be around here somewhere, it is a classic. I thought I might find a version in TinyBASIC but I am too much into getting a turtle string to repeat to hunt for it at moment.

The VAL command just converts a string to a number. For EVAL type functionality, the CHAIN command is somewhat similar.