Next: , Previous: Obtaining Properties of Format Types, Up: Input and Output Formats


2.2.4 Numeric Formatting Styles

Each of the basic numeric formats (F, E, COMMA, DOT, DOLLAR, PCT) and custom currency formats (CCA, CCB, CCC, CCD, CCE) has an associated numeric formatting style, represented by struct fmt_number_style. Input and output conversion of formats that have numeric styles is determined mainly by the style, although the formatting rules have special cases that are not represented within the style.

— Structure: struct fmt_number_style

A structure type with the following members:

struct substring neg_prefix
struct substring prefix
struct substring suffix
struct substring neg_suffix
A set of strings used a prefix to negative numbers, a prefix to every number, a suffix to every number, and a suffix to negative numbers, respectively. Each of these strings is no more than FMT_STYLE_AFFIX_MAX bytes (currently 16) bytes in length. These strings must be freed with ss_dealloc when no longer needed.
decimal
The character used as a decimal point. It must be either `.' or `,'.
grouping
The character used for grouping digits to the left of the decimal point. It may be `.' or `,', in which case it must not be equal to decimal, or it may be set to 0 to disable grouping.

The following functions are provided for working with numeric formatting styles.

— Function: void fmt_number_style_init (struct fmt_number_style *style)

Initialises a struct fmt_number_style with all of the prefixes and suffixes set to the empty string, `.' as the decimal point character, and grouping disables.

— Function: void fmt_number_style_destroy (struct fmt_number_style *style)

Destroys style, freeing its storage.

— Function: struct fmt_number_style *fmt_create (void)

A function which creates an array of all the styles used by pspp, and calls fmt_number_style_init on each of them.

— Function: void fmt_done (struct fmt_number_style *styles)

A wrapper function which takes an array of struct fmt_number_style, calls fmt_number_style_destroy on each of them, and then frees the array.

— Function: int fmt_affix_width (const struct fmt_number_style *style)

Returns the total length of style's prefix and suffix.

— Function: int fmt_neg_affix_width (const struct fmt_number_style *style)

Returns the total length of style's neg_prefix and neg_suffix.

PSPP maintains a global set of number styles for each of the basic numeric formats and custom currency formats. The following functions work with these global styles:

— Function: const struct fmt_number_style * fmt_get_style (enum fmt_type type)

Returns the numeric style for the given format type.

— Function: void fmt_check_style (const struct fmt_number_style *style)

Asserts that style is self consistent.

— Function: const char * fmt_name (enum fmt_type type)

Returns the name of the given format type.