Numbers handling - Petewg/harbour-core GitHub Wiki

πŸ”™ Functions-by-category

Numbers handling functions are those that receive a numeric argument, for their main parameter, and do things (such as calculations, transforms or some other kind of processing) with this numeric value.


  • Abs( <nExp> ) ➜ nPositive
    returns the absolute value of the passed argument. The result is always greater than or equal to 0 (zero).

  • Exp(<nExponent>) ➜ nAntilogarithm
    returns a numeric value that is equivalent to the value of e raised to the specified power. The maximum value of <nExponent> is 46 otherwise a numeric overflow occurs. It's the inverse function of 'LOG()'.

  • hb_ntoc( <nValue>, [nDecs] ) ➜ cValue
    This function converts the given numeric value to a string value, while (trying to) keep all or at least nDecs significant digits in double numbers, unless <nDecs> is lesser than actual decimal digits of <nValue>, in which case the result will be rounded.
    SET DECIMAL setting has no effect on the returned value (ignored), which means that, unlike f.e. Str(), all non-sginficant digits (e.g.: trailing decimal zeros) will be removed. Likewise, all leading empty spaces will be trimmed.
    Returns stringified value of <nValue>, preserving all (or at least <nDecs>) significant digits, if any.
    Interestingly, if <nValue> is NIL or not numeric, this function will return a null string and, unlike Str(), will NOT cause an RTE.
    NOTE: new function, available after 2016-06-20 21:59 UTC+0200 commit (it is not available in earlier versions).

  • hb_ntos(<nValue>) ➜ cSstring
    converts any numeric value to a string, trimming all the surplus spaces, equivalent to 'LTrim(Str( nNumber ))'.
    Returns converted value or null string, if the nValue passed is not numeric (or not passed).

  • hb_NumToHex(<nDecNumber> [, <nHexDigits> ]) ➜ cHexNumber
    converts a decimal number into a hexadecimal number. You can specify the length of the resulting hexadecimal number with <nHexDigits>.

  • hb_Rand32() ➜ nRandomInt
    returns a random integer between 0 and 0xFFFFFFFF inclusive. - (0xFFFFFFFF = 4.294.967.295)

  • hb_Random( [<x> [, <y>]] ) ➜ nRandomReal
    returns a real number <n> so that: 0 <= n < 1 (if no params passed), or 0 <= n < x (if only <x> passed), or x <= n < y (if <x>, <y> passed). Note: value of <y> (if any), is NOT included in values returned.

  • hb_RandomInt( [<x> [, <y>]] ) ➜ nRandomInt
    returns an integer number <n> so that: 1 <= n <= x (when only x passed), or x <= n <= y (when x and y passed), or 0s and 1s almost evenly distributed (when no params passed). Note: values of x,y (if any), are INCLUDED in values returned.

  • hb_RandomIntMax() ➜ 2147483645

  • hb_RandomSeed( <nSeed> ) ➜ NIL
    seeds (i.e. initializes) the random number generator used by hb_Rand* family functions. It may be invoked once, before calling a 'randomizer' function. If the parameter nSeed is 0, then first call to hb_Random() or hb_RandomInt() activates initialization which generates new seed using current time in milliseconds and HVM stack address (for MT modes). If repeatable results needed from hb_Random() and hb_RandomInt() then the seed should be initialized for each thread with some fixed value i.e. hb_RandomSeed( 123456789 )

  • I2Bin(<nInteger>) ➜ cBinaryInteger
    Converts a numeric value to a 16bit binary integer. returns a two-byte character string.
    <nInteger> is an integer numeric value to be converted. Note: Decimal digits are truncated.

  • Int( <nExp> ) ➜ nInteger
    returns the integer part of a numeric value, by truncating (but not rounding) all of its decimal digits (if any). The decimal part is lost.

  • L2Bin(<nExp> ) ➜ cBinaryInteger
    returns a four-byte character string formatted as a 32-bit binary integer.

  • LenNum( <nNumber> ) ➜ nLength
    returns the number of digits plus the decimal point, the decimal digits and the minus sign (if any) of a number, i.e. the number of characters needed to display/print the number.

  • Log( <nExp> ) ➜ nNaturalLog
    returns the natural logarithm of a number.

  • Max(<xExp1>, <xExp2>) ➜ xLarger
    returns the larger numeric, date, datetime or logic value. On logic value larger is .T.

  • Sqrt( <nNumber> ) ➜ nSquareRoot
    returns the square root of <nNumber>. The precision of this evaluation is based solely on the settings of the SET DECIMAL TO command. Any negative number passed as <nNumber> will always return a 0.

  • Str(<nNumber>, [<nLength>], [<nDecimals>]) ➜ cNumber
    converts a numeric expression <nNumber> to a character string.
    <nLength> is the length of the character string to return, including decimal digits, decimal point, and sign. <nDecimals> is the number of decimal places to return.

  • StrZero( <nNumber>, [<nLength>], [<nDecimals>] ) ➜ cNumber
    converts a numeric expression <nNumber> to a character string, padded with leading zero(s).
    <nNumber> is the numeric expression to be converted to a character string. <nLength> is the length of the character string to return, including decimal digits, decimal point, and sign. <nDecimals> is the number of decimal places to return.


πŸ”™ Functions-by-category

⚠️ **GitHub.com Fallback** ⚠️