Num

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 3


Num (expression) Number

ParameterTypeDescription
expressionString | BooleanString for which to return the numeric form, or
Boolean to return 0 or 1
Function resultNumberNumeric form of the string or Boolean

Description

The Num command returns the numeric form of the String or Boolean expression you pass in expression.

String Expressions

If string consists only of one or more alphabetic characters, Num returns a zero. If string includes alphabetic and numeric characters, Num ignores the alphabetic characters. Thus, Num transforms the string "a1b2c3" into the number 123.

Note: Only the first 32 characters of string are evaluated.

There are three reserved characters that Num treats specially: the decimal separator in the US English version (i.e., the period ".") , the hyphen "-", and "e" or "E". These characters are interpreted as numeric format characters.

The decimal separator is interpreted as a decimal place and must appear embedded in a numeric string.

The hyphen causes the number or exponent to be negative. The hyphen must appear before any negative numeric characters or after the "e" for an exponent. Except for the "e" character, if a hyphen is embedded in a numeric string, the portion of the string after the hyphen is ignored. For example, Num("123-456") returns 123, but Num("-9") returns -9.

The e or E causes any numeric characters to its right to be interpreted as the power of an exponent. The "e" must be embedded in a numeric string. Thus, Num("123e–2") returns 1.23.

Note that when the string includes more than on "e", conversion might give different results under Mac OS and under Windows.

Boolean Expressions

If you pass a Boolean expression, Num returns 1 if the expression is True; otherwise, it returns 0 (zero).

Examples

1. The following example illustrates how Num works when passed a string argument. Each line assigns a number to the vResult variable. The comments describe the results:

   vResult := Num ("ABCD")  ` vResult gets 0 
   vResult := Num ("A1B2C3")  ` vResult gets 123 
   vResult := Num ("123")  ` vResult gets 123 
   vResult := Num ("123.4")  ` vResult gets 123.4
   vResult := Num ("–123")  ` vResult gets –123 
   vResult := Num ("–123e2")  ` vResult gets –12300

2. Here, [Client]Debt is compared with $1000. The Num command applied to these comparisons returns 1 or 0. Multiplying 1 or 0 with a string repeats the string once or returns the empty string. As a result, [Client]Risk gets either "Good" or "Bad":

      ` If client owes less than 1000, a good risk. 
      ` If client owes more than 1000, a bad risk. 
   [Client]Risk:=("Good"*Num ([Client]Debt<1000))+("Bad"*Num([Client]Debt>=1000))

See Also

Logical Operators, String, String Operators.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next