Prices / Percentages

Display native price and percentage columns using full arrays and configurable signs.

Arrays are the newer full, extensible configuration and are preferred for new definitions. Strings remain compatible legacy shorthand/quick syntax. Option keys are specific to each native field type.

Use type price for a leading sign, or percentage for a trailing sign. col must be the numeric column selected by the owning query.

$td_fields = [];
array_push($td_fields, [
    'type' => 'price', 'col' => 'AMOUNT', 'sign' => 'CAD '
]);
array_push($td_fields, [
    'type' => 'percentage', 'col' => 'RATE', 'sign' => '%'
]);

Normal presentation uses two decimal places and groups whole digits: CAD 1,234.57 or 12.35%. The default sign is $ for price and % for percentage. Include spacing in a custom sign when desired. This existing sign property supplies the price prefix or percentage suffix; a separate text prefix/suffix property is unnecessary.

Supported common presentation properties include privilege, class, attributes, title and icon. Formatting changes the display, not the underlying stored value. Keep amounts numeric in calculations and exports; do not replace numeric columns with preformatted HTML.

Preserve fractional precision

$td_fields[] = [
    'type'=>'price', 'col'=>'AMOUNT', 'sign'=>'CAD ',
    'decimals'=>'trim'
];

decimals=trim preserves the stored decimal digits while trimming unnecessary trailing zeros. Omit it for the default two-place presentation; this branch does not provide arbitrary numeric decimal-scale configuration. Keep exact numeric values in storage and CSV; presentation is not per-message accounting rounding.

For nullable numeric calculations, set a plain-text empty_text label: ['type'=>'price', 'col'=>'PROFIT', 'empty_text'=>'Unknown']. Price and percentage fields escape this label for unavailable nonnumeric values. Numeric zero remains a real formatted value; missing costs must not be converted to zero. Existing numeric formatting is unchanged.