CAPL Script

Strtod

Syntax

int strtod(char s[], double& result);

int strtod(char s[], dword startIndex, double& result);

Function

Converts the stringsto a floating point number. The string must have the format[whitespace][sign][digits][.digits][{d|D|e|E}[sign]digits]. Whitespace: may consist of space and tab characters, which are ignoredsign: is either plus (+) or minus (-)digits: are one or more decimal digits.If no digits appear before the radix character, at least one must appear after the radix character. The decimal digits can be followed by an exponent, which consists of an introductory letter (d, D, e, or E) and an optionally signed integer. If neither an exponent part nor a radix character appears, a radix character is assumed to follow the last digit in the string.

Parameters

s String to be converted.

result Contains the converted value after the call. The value is 0 if the string can’t be converted to a number. It is the largest possible positive/negative number in case of overflow.

startIndex Position in s where the conversion shall begin.

Return Values

-2: Ifsis empty orstartIndexis larger thanstrlen(s).

-1: An overflow occurs.

Otherwise, returns the index of the first character after the number.

char s[20] = "-1.23 2.4E3";double number1, number2;int res;res = strtod(s, number1);write("number1: %g, res: %d", number1, res); // output: number1: -1.23, res: 5res = strtod(s, res, number2);write("number2: %g, res: %d", number2, res); // output: number2: 2400, res: 11