IntlFormatNumber

Format a number in a localized manner.

Synopsis

int32 intlFormatNumber(Item locItem,const NumericSpec *spec,uint32 whole, uint32 frac,bool negative, bool doFrac,unichar *result, uint32 resultSize);

Description

This function formats a number according to the rules contained in the NumericSpec structure. The NumericSpec structure is normally taken from a Locale structure. The Locale structure contains three initialized NumericSpec structures (loc_Numbers, loc_Currency, and loc_SmallCurrency) which let you format numbers in an appropriate manner for the current system.

You can create your own NumericSpec structure which lets you use intlFormatNumber() to handle custom formatting needs. The fields in the structure have the following meaning:

Arguments

locItem
A Locale Item, as obtained from intlOpenLocale().
spec
The formatting template describing the number layout. This structure is typically taken from a Locale structure (loc_Numbers, loc_Currency, loc_SmallCurrency), but it can also be built up by the title for custom formatting.
whole
The whole component of the number to format. (The part of the number to the left of the radix character.)
frac
The decimal component of the number to format. (The part of the number to the right of the radix character.). This is specified in number of billionth. For example, to represent .5, you would use 500000000. To represent .0004, you would use 400000.
negative
TRUE if the number is negative, and FALSE
if the number is positive.
doFrac
TRUE if a complete number with a decimal mark and decimal digits is desired. FALSE if only the whole part of the number should be output.
result
Where the result of the formatting is put.
resultSize
The number of bytes available in the result buffer. This limits the number of bytes which are put into the buffer.

Return Value

If positive, then the number of characters in the result buffer. If negative, then an error code. The string copied into the result buffer is guaranteed to be NULL-terminated.

greater than or equal to 0 Number of characters copied.

INTL_ERR_BADNUMERICSPEC - The pointer to the NumericSpec structure was bad.

INTL_ERR_NORESULTBUFFER- "result" was NULL.

INTL_ERR_BUFFERTOOSMALL - There was not enough room in the result buffer.

INTL_ERR_BADITEM loc- Item was not an existing Locale Item.

Implementation

Folio call implemented in international folio V24.

Associated Files

intl.h

See Also

intlOpenLocale(), intlFormatDate()