Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: Français - Português - 日本語 - Русский

Please note that the recommended version of Scilab is 6.1.1. This page might be outdated.
However, this page did not exist in the previous stable version.

Scilab Help >> Strings > strtod


parse and convert literal numbers STRings TO Decimal numbers


d =  strtod(str [,decimalseparator])
[d, tails] = strtod(str [,decimalseparator])



single component, vector, or matrix of text (strings).


the decimal separator chosen: "." (by default) or ",".


scalar, vector, or matrix of decimal numbers.


a string or matrix of strings: remaining parts of str after the numerical heads (if any).


[d, tails] = strtod(str) parses each string of str and tries to interpret its content as a decimal number:

  • If it succeeds, at least for the heading part of str(i), the corresponding decimal number is returned in d(i). If any, the trailing part of str(i) is ignored and returned in tails(i); otherwise, tails(i) returns "".
  • Otherwise, d(i) returns %nan, and tails(i) is the whole str(i).

  • Complex numbers: strtod(..) parses and returns only their real part, provided that it is writen before their imaginary part.
  • strtod(..) does not acknowledge any thousands separator, neither " ", nor "," nor any other one.
  • strtod(..) parses strings only against decimal numbers. It does not interpret hexadecimal, octal or other radix strings.
  • strtod(..) does not interpret any name of Scilab predefined or user-defined variables or special strings for %inf or %nan. Hence we have:
    s = ["-0.034" "- 0.034"  "+1234.5678" "1234 5678"
         "-.764"  "+.432"    "12,231.7"   "-5.458,871"
         "1e43"   "-3.5d-12" "-1.2+i"     "i+1.2"
         ""       "%inf"     "Inf"        "-Inf"
         "%i"     "%pi"      "%e"         "%eps"
         "%F"     "0x19B"    "#14C4"      "o5745"
      s  =
    !-0.034  - 0.034   +1234.5678  1234 5678   !
    !-.764   +.432     12,231.7    -5.458,871  !
    !1e43    -3.5d-12  -1.2+i      i+1.2       !
    !        %inf      Inf         -Inf        !
    !%i      %pi       %e          %eps        !
    !%F      0x19B     #14C4       o5745       !
    --> strtod(s)
     ans  =
      -0.034       Nan         1234.5678   1234.
      -0.764       0.432       12.        -5.458
       1.000D+43  -3.500D-12  -1.2         Nan
       Nan         Nan         Nan         Nan
       Nan         Nan         Nan         Nan
       Nan         0.          Nan         Nan
  • strtod(..) does not interpret escape sequences "\n", "\t", etc.
  • This function is based on the strtod C function which causes different behaviors on Windows and Linux. In fact, on Windows, it is possible to use "d" or "D" for exponents, but it is not possible to use hexadecimal numbers.


s = ["123.556 abc " ".543"      "#58B" "0x73 " "%inf"
     "-1.47e-71"    "67,432.57" " 23,5" "-,57" "Inf" ]
[num, trail] = strtod(s);
num, "/"+trail+"/"

// With "," as decimal separator:
[num, trail] = strtod(s, ",");
num, "/"+trail+"/"

See also

  • evstr — evaluation of expressions
  • isnum — tests if a string represents a number
  • isdigit — check that characters of a string are digits between 0 and 9
  • bin2dec — convert from binary to decimal
  • oct2dec — convert from octal to decimal
  • hex2dec — convert from hexadecimal to decimal


5.5.0 Option decimalseparator introduced (SEP 97).
5.4.1 If str does not contain any numerical value, d now returns Nan instead of 0.
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:02:52 CET 2017