Developing Apama Applications > Apama EPL Reference > Types > Primitive and string data types > decimal
decimal
A signed decimal floating point number. Either a decimal point (.) or an exponent symbol (e) must be present within the number for it to be a valid decimal, plus a decimal suffix (d) to distinguish it from a float.
When perfect accuracy of base-10 numbers is a requirement, use the decimal data type in place of the float data type. When extremely small floating point variations are acceptable, you might choose to use the float data type to obtain better performance.
For information about Apama client API support for the decimal data type, see What's New in Apama.
Values
Values of the decimal type are a finite-precision approximation of the mathematical real numbers, encoded as 64-bit decimal floating-point values consisting of sign, significand, and exponent, as defined by the “IEEE Standard for Floating-Point Arithmetic, ANSI/IEEE Standard 754 -2008 (IEEE, New York)”. Values of the decimal type have a precision of exactly 16 decimal digits.
The largest positive decimal floating point value that can be stored in a variable of type decimal is
9.999999999999999 * 10384
The smallest nonzero positive value that can be stored is
10-398
In addition to the usual positive and negative numbers, the IEEE standard also defines positive and negative zeros, positive and negative infinities, and Not-a-Number values.
For information about how the correlator handles these values, see Support for IEEE 754 special values. For information about how the correlator handles these values, see "Support for IEEE 754 special values" later in this section of the documentation.
Because decimal values are of finite precision, they cannot accurately represent all values, for example, recurring decimals or irrational numbers. However, decimals have the advantage over floats in that provided a decimal literal does not exceed the 16-place precision, it will be represented exactly within the correlator. The following program illustrates the difference between decimal and float types in this regard:
monitor foo
{
   action onload()
   {
      float f;
      decimal d;
      f := 0.1;
      d := 0.1d;
      print f.formatFixed(18);
      print d.formatFixed(18);
   }
}
This program produces the output below.. Note the small error in the least significant digit in the float, versus the decimal.
0.100000000000000006
0.100000000000000000
There are a number of decimal constants provided in EPL. See Support for IEEE 754 special values.
Operators
The EPL operators that you can use with decimal types are the same operators that you can use with float types. See float "Operators" in the next section of the documentation.
Methods
The methods that you can call on decimal types are the same methods that you can call on float types. See float "Methods" in the next section of this documentation. There are a few differences according to whether the method is called on a decimal or float type and these are noted in the descriptions.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.