The Numeric Class

Details about the Numeric class and its public members.

Values for this data type are limited to 15 significant digits.

Syntax

Numeric

Methods

Table 1. Object Methods
Name Description
abs()
Returns the absolute value.
atan2(Numeric x)
Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta)
byteValue()
Returns the value converted to a byte.
cbrt()
Returns the cube root of a numeric value.
ceil()
Returns the smallest numeric value that is greater than or equal to the value and is equal to a mathematical integer.
cos()
Returns the trigonometric cosine of an angle.
cosh()
Returns the hyperbolic cosine of a numeric value.
exp()
Returns the base -e exponential.
floor()
Returns the largest numeric value that is less than or equal to the value and is equal to a mathematical integer.
format("format-string")

Converts the value to a string representation defined by a format string.

For example, for DECIMAL and FLOAT data types, format-string consists of pound signs (#) that represent digits and a decimal point; that is, "###.##" produces three places to the left of the decimal point and exactly two to the right. Additional options for the string are listed in the Usage section, format.

getExponent()
Returns the unbiased exponent used in the representation of a numeric value.
intValue()
Returns the value converted to an integer.
isInfinite()
Returns TRUE if the value has infinite value
isNaN()
Returns TRUE if the value is not a number
isNull()

Returns true if toDouble() is 0 and the object is tagged as null, otherwise false. This is the case for null valued input variables read from the input stream.

For backward compatibility, null values do not have special behavior when used with the various operators. Specifically a numeric input variable that is null behaves in arithmetic like the 0 value.

log()
Returns the natural logarithm (base e) of a numeric value.
log10()
Returns the base 10 logarithm of a numeric value.
max(Numeric b)
Returns the greater of two values.
min(Numeric b)
Returns the smaller of two values.
rint()
Returns the Numeric value that is closest in value to the value and is equal to a mathematical integer.
round()
Returns the closes integer to the value.
signum()
Returns the signum function of the value; zero if the value is zero, 1.0 if the value is greater than zero, -1.0 if the value is less than zero.
sin()
Returns the trigonometric sine, measured in radians.
sinh()
Returns the hyperbolic sine of a numeric value.
sqrt()
Returns the tangent of an angle measured in radians.
tan()
Returns the tangent of an angle measured in radians.
tanh()
Returns the hyperbolic tangent of a numeric value.
toBoolean()

Returns the Boolean false when the value is 0. Returns true for any other value.

toChar()
Returns the unicode character representation of a numeric value.
toColor()

Returns a color object. The value is interpreted as a RGB integer.

toDegrees()

Converts the value from radians to degrees.

toRadians()

Converts the value from degrees to radians.

toString()
Converts the value to a string representation.
getPhysicalPageNumber()
Gets the current page number of the physical page.
getTotalNumberOfPhysicalPages()
Gets the total number of physical pages.
getPageNumber(String pageName)
Gets the page number of the specified page.
getTotalNumberOfPages(String pageName)
Gets the total number of pages for the specified page.

Usage

Important: This data type is limited to 15 significant digits.

With RTL classes, it is not possible to create and subclass objects. The new keyword is not supported.

abs()

abs()

Returns the absolute value of an int value:

cos()

cos()

Returns the trigonometric cosine of an angle. However, If the value is NaN or an infinity, then the result is NaN.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

sin()

sin() 

Returns the trigonometric sine of an angle. However,

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

tan()

tan() 
Returns the trigonometric tangent of an angle. Special cases:
  • If the value is NaN or an infinity, then the result is NaN.
  • If the value is zero, then the result is a zero with the same sign as the value.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

byteValue()

byteValue() 

Returns the value converted to a byte .

cbrt()

cbrt()

Returns the cube root of a double value. For positive finite x, cbrt(-x) == -cbrt(x); that is, the cube root of a negative value is the negative of the cube root of that value's magnitude.

Special cases:

The computed result must be within 1 ulp of the exact result.

ceil()

ceil()

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the value and is equal to a mathematical integer.

Special cases:

Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x).

cosh()

cosh() 

Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be (ex + e-x)/2 where e is Euler's number.

Special cases:

The computed result must be within 2.5 ulps of the exact result.

exp()

exp() 

Returns Euler's number e raised to the power of a double value. Special cases:

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

floor()

floor() 

Returns the largest (closest to positive infinity) double value that is less than or equal to the value and is equal to a mathematical integer.

Special cases:

getExponent()

getExponent() 

Returns the unbiased exponent used in the representation of a float.

Special cases:
  • If the value is NaN or infinite, then the result is Float. MAX_EXPONENT + 1.
  • If the value is zero or subnormal, then the result is Float. MIN_EXPONENT -1.

intValue()

intValue() 

returns the value converted to an integer (signed 32 bit)

isInfinite()

isInfinite()

returns the Boolean value true in case the value has the infinite value

isNaN()

isNaN() 

returns the Boolean value true in case that the value is not a number

log()

log()

Returns the natural logarithm (base e) of a double value.

Special cases:
  • If the value is NaN or less than zero, then the result is NaN.
  • If the value is positive infinity, then the result is positive infinity.
  • If the value is positive zero or negative zero, then the result is negative infinity.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

log10()

log10() 

Returns the base 10 logarithm of a double value.

Special cases:
  • If the value is NaN or less than zero, then the result is NaN.
  • If the value is positive infinity, then the result is positive infinity.
  • If the value is positive zero or negative zero, then the result is negative infinity.
  • If the value is equal to 10n for integer n, then the result is n.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

rint()

rint() 

Returns the double (floating-point) value that is closest in value to the value and is equal to a mathematical integer. If two double values that are mathematical integers are equally close, the result is the integer value that is even.

Special cases:
  • If the value is already equal to a mathematical integer, then the result is the same as the value.
  • If the value is NaN or an infinity or positive zero or negative zero, then the result is the same as the value.

Returns:

the closest floating-point value to a that is equal to a mathematical integer.

round()

round() 

Returns the closest int to the value. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int. In other words, the result is equal to the value of the expression:

(int)Math.floor(a + 0.5f)

Special cases:
  • If the value is NaN, the result is 0.
  • If the value is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE.
  • If the value is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.

See Also:

Integer.MAX_VALUE, Integer.MIN_VALUE

signum ()

signum () 

Returns the signum function of the value; zero if the value is zero, 1.0 if the value is greater than zero, -1.0 if the value is less than zero.

Special Cases:
  • If the value is NaN, then the result is NaN.
  • If the value is positive zero or negative zero, then the result is the same as the value.

Returns:

the signum function of the value

sinh()

sinh() 

Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Euler's number.

Special cases:
  • If the value is NaN, then the result is NaN.
  • If the value is infinite, then the result is an infinity with the same sign as the value.
  • If the value is zero, then the result is a zero with the same sign as the value.

The computed result must be within 2.5 ulps of the exact result.

sqrt()

sqrt() 

Returns the correctly rounded positive square root of a double value.

Special cases:
  • If the value is NaN or less than zero, then the result is NaN.
  • If the value is positive infinity, then the result is positive infinity.
  • If the value is positive zero or negative zero, then the result is the same as the value.

Otherwise, the result is the double value closest to the true mathematical square root of the value

tanh()

tanh() 

Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be (ex - e-x)/(ex + e-x), in other words, sinh(x)/cosh(x). Note that the absolute value of the exact tanh is always less than 1.

Special cases:
  • If the value is NaN, then the result is NaN.
  • If the value is zero, then the result is a zero with the same sign as the value.
  • If the value is positive infinity, then the result is +1.0.
  • If the value is negative infinity, then the result is -1.0.

The computed result must be within 2.5 ulps of the exact result. The result of tanh for any finite input must have an absolute value less than or equal to 1. Note that once the exact result of tanh is within 1/2 of an ulp of the limit value of ±1, correctly signed ±1.0 should be returned.

toChar()

toChar() 

Converts the value to a unicode character representation.

For example, 65.toChar() yields "A".

atan2(Numeric x))

atan2(Numeric x)) 

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.

Special cases:
  • If either value is NaN, then the result is NaN.
  • If the value is positive zero and the argument is positive, or the value is positive and finite and the argument is positive infinity, then the result is positive zero.
  • If the value is negative zero and the argument is positive, or the value is negative and finite and the argument is positive infinity, then the result is negative zero.
  • If the value is positive zero and the argument is negative, or the value is positive and finite and the argument is negative infinity, then the result is the double value closest to pi.
  • If the value is negative zero and the argument is negative, or the value is negative and finite and the argument is negative infinity, then the result is the double value closest to -pi.
  • If the value is positive and the argument is positive zero or negative zero, or the value is positive infinity and the argument is finite, then the result is the double value closest to pi/2.
  • If the value is negative and the argument is positive zero or negative zero, or the value is negative infinity and the argument is finite, then the result is the double value closest to -pi/2.
  • If both value and argument are positive infinity, then the result is the double value closest to pi/4.
  • If the value is positive infinity and the argument is negative infinity, then the result is the double value closest to 3*pi/4.
  • If the value is negative infinity and the argument is positive infinity, then the result is the double value closest to -pi/4.
  • If both value and argument are negative infinity, then the result is the double value closest to -3*pi/4.

The computed result must be within 2 ulps of the exact result. Results must be semi-monotonic.

Parameters:

x - the abscissa coordinate

max(Numeric b)

max(b)

Returns the greater of two int values. That is, the result is the argument closer to the value of Integer.MAX_VALUE. If the argument has the same value as the object's value the result is that same value.

Parameters:

  • b - an argument.

See Also: Long.MAX_VALUE

min(Numeric b)

min( b) 

Returns the smaller of two int values. That is, the result is the argument closer to the value of Integer.MIN_VALUE. If the argument has the same value as the objects value the result is that same value.

Parameters:

See Also: Long.MIN_VALUE

format("format-string")

format("format-string") 

Converts the value to a string representation defined by a format string. The format string syntax is compatible to the D4GL "USING" format string. The formatting takes the values of the environment variables DBFORMAT and DBMONEY into account.

Table 2. Formatting symbols
Character Description
* Fills with asterisks any position that would otherwise be blank.
& Fills with zeros any position that would otherwise be blank.
# This does not change any blank positions in the display.
< Causes left alignment.
, (comma) Defines the position of the thousands separator. The thousands separator is not displayed if there are no digits to the left. By default, the thousands separator is a comma, but it can be another character as defined by DBFORMAT.
. (period) Defines the position of the decimal separator. Only a single decimal separator may be specified. By default, the decimal separator is a period, however it can be another character as defined by DBMONEY or DBFORMAT.
- Displays a minus sign for negative numbers.
$ This is the placeholder for the front specification of DBMONEY or DBFORMAT.
( Displayed as left parentheses for negative numbers (accounting parentheses).
) Displayed as right parentheses for negative numbers (accounting parentheses).

Examples

  1. This example converts the number 65 to "A", its unicode character representation: 65.toChar()
  2. This example formats the numeric value of overall total as a string: overalltotal.format("###.##")