TFormattableNumber, derived from TFormattable, and TNumberFormatter, derived from TFormatter, provide the mechanism for scanning and formatting numbers. Classes derived from TNumberFormatter provide formatting for various numbering systems used throughout the world. To format numbers in the Western decimal numbering system, use TPositionalNumberFormatter and its derived classes.
TFormattableNumber stores a numeric value as a double
, allowing it to be formatted by a number formatter.
TNumberFormatter is the abstract base class for classes that scan and format numerical data. TNumberFormatter manipulates numerical data wrapped in a TFormattableNumber instance. The system provides TNumberFormatter subclasses that cover most of the commonly used number formats in most languages:
- TAdditiveNumberFormatter provides the protocol for manipulating numbers based on an additive system--numbering systems in which each digit has an inherent value and the total value of a number is determined by adding the value of each digit. Several derived classes provide implementations of standard additive numbering systems:
- THebrewNumberFormatter correctly formats and scans Hebrew numerals, using the Hebrew alphabet.
- TRomanNumberFormatter formats and scans Roman numerals. TRomanNumberFormatter lets you specify the case of formatted numbers and control the extent to which subtraction is used to represent certain numbers (for example, 4 as IIII or IV).
- THybridNumberFormatter formats and scans numerals for numbering systems that have a threshold at which number values are determined by multiplying the individual digits in the number in some way.
- THanNumberFormatter, derived from THybridNumberFormatter, formats and scans Han numbers, the numbering system used commonly in many parts of East Asia.
- TOutlineNumberFormatter allows you to implement an outline-style numbering scheme--for example, a sequence such as {a,b,c,...,z,aa,bb,...} where a has the value 1, b has the value 2, aa has the value 27, and so on.
- TPositionalNumberFormatter provides the protocol for manipulating integers within a value-based system--numbering systems in which the total value of a number is determined by both the value of each digit and the position of the digit within the number. You can use TPositionalNumberFormatter or a derived class to format numbers according to the decimal numbering system used in the West.
The system includes the following subclass of TPositionalNumberFormatter that provides additional functionality for handling non-integers within a value-based system:
- TRationalNumberFormatter formats non-integer values as a ratio of two integers--a fraction (for example, 22/7). TRationalNumberFormatter lets you specify:
- Whether to format into a proper (3 1/7) or improper fraction (22/7)
- The character used to separate the integer from the fraction
- The character used to separate the numerator from the denominator
- The number format used to format the integers in the fraction
TUniversalNumberFormatter, a special class derived from TFloatingPointNumberFormatter, provides a formatter with a universal range. This class can handle any number, including infinity and NaNs. TUniversalNumberFormatter is the default formatter for all other number formatting classes, guaranteeing that you will get a result whenever you format data from a binary number into a text representation. You will not need to use this class directly.
TNumerals provides the character-value mapping rules used by a TNumberFormatter. Two subclasses are provided:
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.
Generated with WebMaker