Skip to main content

Fractional Numbers

Fractional Numbers

Caché supports two different numeric types that can be used to represent fractional numbers:

  • Decimal floating-point: By default, Caché represents fractional numbers using its own decimal floating-point standard ($DECIMAL numbers). This is the preferred format for most uses. It provides the highest level of precision — 18 decimal digits. It is consistent across all system platforms that Caché supports. Decimal floating-point is preferred for data base values. In particular, a fractional number such as 0.1 can be exactly represented using decimal floating-point notation, while the fractional number 0.1 (as well as most decimal fractional numbers) can only be approximated by binary floating-point.

  • Binary floating-point: The IEEE double-precision binary floating point standard is an industry-standard way of representing fractional numbers. IEEE floating point numbers are encoded using binary notation. Binary floating-point representation is usually preferred when doing high-speed calculations because most computers include high-speed hardware for binary floating-point arithmetic. Double-precision binary floating point has a precision of 53 binary bits, which corresponds to 15.95 decimal digits of precision. Binary representation does not correspond exactly to a decimal fraction because a fraction such as 0.1 cannot be represented as a finite sequence of binary fractions. Because most decimal fractions cannot be exactly represented in this binary notation, an IEEE floating point number may differ slightly from the corresponding standard Caché floating point number. When an IEEE floating point number is displayed as a fractional number, the binary bits are often converted to a fractional number with far more than 18 decimal digits. This does not mean that IEEE floating point numbers are more precise than standard Caché fractional numbers. IEEE floating point numbers are able to represent larger and smaller numbers than standard Caché numbers, and support the special values INF (infinity) and NAN (not a number). For further details, refer to the $DOUBLE function.

You can use the $DOUBLE function to convert a Caché standard floating-point number to an IEEE floating point number. You can use the $DECIMAL function to convert an IEEE floating point number to a Caché standard floating-point number.

By default, Caché converts fractional numbers to canonical form, eliminating all leading zeros. Therefore, 0.66 becomes .66. $FNUMBER (most formats) and $JUSTIFY (3-parameter format) always return a fractional number with at least one integer digit; using either of these functions, .66 becomes 0.66.

$FNUMBER and $JUSTIFY can be used to round or pad a numeric to a specified number of fractional digits. Caché rounds up 5 or more, rounds down 4 or less. Padding adds zeroes as fractional digits as needed. The decimal separator character is removed when rounding a fractional number to an integer. The decimal separator character is added when zero-padding an integer to a fractional number.

FeedbackOpens in a new tab