xHarbour Reference Documentation > Function Reference |
Convert a character string containing digits to numeric data type
Val( <cNumber> ) --> nNumber
The function returns a numeric value as the result of the conversion operation. If <cNumber> does not represent a number, the return value is zero.
Val() analyses the parameter <cNumber> which may contain only "+-.0123456789". If <cNumber> contains any other character, a letter, for example, or if a second decimal point is detected, the conversion is terminated and the digits analysed so far are returned as numeric value. Leading blank space characters, however, are ignored.
The function recognizes the SET FIXED and SET DECIMALS settings and rounds the number if <cNumber> contains more decimal places than set with SET DECIMAL.
See also: | Round(), SET DECIMALS, SET FIXED, Str(), Transform() |
Category: | Character functions , Conversion functions |
Source: | rtl\val.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example shows return values of Val() depending on SET FIXED // and SET DECIMALS PROCEDURE Main SET DECIMALS TO 2 SET FIXED ON ? Val( "123.456" ) // result: 123.46 ? Val(" 123.456") // result: 123.46 ? Val( "123*456" ) // result: 123.00 ? Val("x123*456" ) // result: 0.00 ? Val( "-123.456" ) // result: -123.46 ? Val( " -123.456" ) // result: -123.46 ? Val( "- 123.456" ) // result: 0.00 SET DECIMALS TO 3 SET FIXED OFF ? Val( "123.456" ) // result: 123.456 ? Val(" 123.456") // result: 123.456 ? Val( "123*456" ) // result: 123 ? Val("x123*456" ) // result: 0 ? Val( "-123.456" ) // result: -123.456 ? Val( " -123.456" ) // result: -123.456 ? Val( "- 123.456" ) // result: 0.000 RETURN
http://www.xHarbour.com