ToInteger64 (open)

Returns an integer64 representation of a string

Syntax

// Core function, no LOADLIB necessary

INTEGER64 FUNCTION ToInteger64(STRING str, INTEGER64 defaultvalue, INTEGER radix)

Parameters

STRING str

String to convert

INTEGER64 defaultvalue

Value to return if 'str' is not a valid number in the specified number system

INTEGER radix

Number system used in the string, ranging from 2 to 36. If the base is out of range, defaultvalue is returned. This parameter is optional and defaults to 10 (decimal system)

Return value

INTEGER64

The number in the passed string as an integer64, or defaultvalue if the conversion failed.

Description

ToInteger64 parses the string, and attempts to return an integer of the specified base (radix). If the function failed to parse the specified string, it will return @italic defaultvalue

A base of 10 indicates that a decimal number should be converted, 8 octal, 16 hexadecimal, and so on.

Examples

// The following examples all return 15
INTEGER64 example1 := ToInteger64("15", -1);
INTEGER64 example2 := ToInteger64("15", -1, 10);
INTEGER64 example3 := ToInteger64("F", -1, 16);
INTEGER64 example4 := ToInteger64("1111", -1, 2);

// The following faulty strings all return -1
INTEGER64 example5 := ToInteger64("15,99", -1);
INTEGER64 example6 := ToInteger64("5*3", -1, 10);
INTEGER64 example7 := ToInteger64("FFFFFFFFFFFFFFFFF", -1, 16);
INTEGER64 example8 := ToInteger64("22", -1, 2);