Creating a number formatter

The TNumberFormatter formatting and scanning functions divide the conversion operation into two intermediate steps: conversion between a binary number and a TCanonicalNumber, performed by a TCanonicalNumberConverter, and conversion between a TCanonicalNumber and text.

When you derive a class from TNumberFormatter, do not override the Format and Scan member functions provided by TNumberFormatter. Instead, override the protected member functions that perform the conversion between text data and the canonical number:

TextToCanonicalNumber converts a text string into a canonical number. The Scan function calls this function and passes the resulting canonical number to a TCanonicalNumberConverter.

CanonicalNumberToText converts a canonical number to a text string. The Format function calls this function after it calls a TCanonicalNumberConverter to convert a binary number to a canonical number.


The TNumberFormatter class handles setting the TCanonicalNumberConverter fields, using a set of default values where appropriate. If you want to understand this behavior, see the section "Numerics" in the manual Foundation Services for more information on using canonical numbers.

TIP The characters used to represent numbers by any particular instance of TNumberFormatter are determined by that formatter's TNumerals data member. You can create a TNumerals instance that maps a value to any character you want, regardless of whether the character is defined by Unicode as a digit. When you create your own number formatter, request information about whether a character is a digit or a character's numeric value from the formatter's TNumerals data member, not from the TUnicode member functions IsDigit or DigitValue. If you use this technique, your number formatter should work with any TNumerals instance a user chooses.


[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