Bookshelf Home | Contents | Index | PDF

### Numbers in Siebel eScript

This topic describes the various notations for numeric literals.

NOTE:  The notations provided in this section are not data types and should not be used as data types in declarations for strongly typed variables.

NOTE:  Numbers that contain characters other than a decimal point, except in hexadecimal and scientific notation, are treated as string values in eScript. For example, eScript treats the number 100,000 (notice the comma) as a string.

#### Integer

Integers are positive and negative whole numbers and zero. Integer constants and literals can be expressed in decimal, hexadecimal, or octal notation. Decimal constants and literals are expressed by using the decimal representation. See the following two sections to learn how to express hexadecimal and octal integers.

NOTE:  A variable cannot be strongly typed as an integer. You can use the primitive type float, and it's value can be used as an integer.

Hexadecimal notation uses base-16 digits from the sets of 0-9 and A-F or a-f. These digits are preceded by 0x. Case sensitivity does not apply to hexadecimal notation in Siebel eScript. Examples are:

0x1, 0x01, 0x100, 0x1F, 0x1f, 0xABCD
var a = 0x1b2E;

The decimal equivalents are:

1, 1, 256, 31, 31, 43981
var a = 6958

#### Octal

Octal notation uses base-8 digits from the set of 0-7. These digits are preceded by a zero. Examples are:

00, 05, 077
var a = 0143;

The decimal equivalents are:

0, 5, 63
var a = 99

#### Floating Point

Floating-point numbers are numbers with fractional parts that are indicated by decimal notation, such as 10.33.

NOTE:  Floating-point numbers are often referred to as floats. Do not confuse the familiar connotation of float with the eScript float primitive data type.

CAUTION:  The assignment of a floating-point number to a variable may cause a loss in precision due to a limit in memory for decimal-to-binary conversion. Numbers that may be stored with a small precision error are decimal numbers that do not convert to a finite binary representation. For example, the statement var x = 142871.45 may result in x being stored as 142871.450000000001. These small precision errors will likely have little effect on precision of subsequent calculations, depending on their context. However, a number's representation may be unexpectedly too large for the field in which it displays, resulting in the error message "Value too long for field %1 (maximum size %2)."

To prevent floating-point precision errors, use the toFixed() Method at appropriate points in calculations or when assigning variable values. For example, use x.toFixed(2) in calculations instead of using variable x as declared above.

#### Decimal

Decimal floats use the same digits as decimal integers but use a period to indicate a fractional part. Examples are:

0.32, 1.44, 99.44
var a = 100.55 + .45;

#### Scientific

Scientific notation is useful in expressing very large and very small numbers. It uses the decimal digits in conjunction with exponential notation, represented by `e` or `E`. Scientific notation is also referred to as exponential notation. Examples are:

4.087e2, 4.087E2, 4.087e+2, 4.087E-2
var a = 5.321e31 + 9.333e-2;

The decimal equivalents are:

408.7, 408.7, 408.7, 0.04087
var a = 53210000000000000000000000000000 + 0.09333

#### NaN

NaN means "not a number," and NaN is an abbreviation for the phrase. NaN is not a data type, but is instead a value. However, NaN does not have a literal representation. To test for NaN, the function, isNaN(), must be used, as illustrated in the following fragment:

var Test = "a string";
if (isNaN(parseInt(Test)))
TheApplication().RaiseErrorText("Test is Not a Number");

When the parseInt() function tries to parse the string` "a string"` into an integer, it returns NaN, because `"a string"` does not represent a number as the string `"22" `does.

#### Number Constants in Siebel eScript

Several numeric constants, as shown in Table 4, can be accessed as properties of the Number object, though they do not have a literal representation.

Table 4. Numeric Constants in Siebel eScript
Constant
Value
Description

`Number.MAX_VALUE`

1.7976931348623157e+308

Largest number (positive)

`Number.MIN_VALUE`

2.2250738585072014e-308

Smallest positive nonzero value

`Number.NaN`

NaN

Not a number

`Number.POSITIVE_INFINITY`

Infinity

Number greater than `MAX_VALUE`

`Number.NEGATIVE_INFINITY`

-Infinity

Number less than `MIN_VALUE`

 Siebel eScript Language Reference