CoolCMS API

QuantityFormat
in package

FinalYes

The one place that decides how a quantity (and a decimal amount with the same rules) is shown to people: a whole number without decimals ("2"), a real decimal with the needed places only ("2,5", "2,25").

Invoice quantities are decimal(8,2) (work-list hours such as 2.5 h), so the database returns "2.00"; printing that as is looked like a fractional quantity on every form, listing, PDF and e-mail. Every output of a document quantity goes through here: the invoice and invoice template forms, the PDF (InvoicePdfGenerator::formatQuantity()), the credit note tables (Latte filter |quantity, QuantityLatteExtension) and the e-mail, which carries the PDF.

Pure and static: no locale lookup; the caller passes the decimal separator (comma by default, the document PDF passes the one of its localization).

Table of Contents

Constants

QUANTITY_SCALE  : int = 2
Scale of a document quantity (`invoice_items.quantity` is `decimal(8,2)`).

Methods

decimal()  : string|null
Formats a decimal with the rules of {@see quantity()} and the given column scale.
quantity()  : string|null
Formats a quantity: whole without decimals, a decimal without trailing zeros; `null` stays `null` (a missing shipper or payment line), a non-numeric value passes unchanged.

Constants

QUANTITY_SCALE

Scale of a document quantity (`invoice_items.quantity` is `decimal(8,2)`).

public int QUANTITY_SCALE = 2

Methods

decimal()

Formats a decimal with the rules of {@see quantity()} and the given column scale.

public static decimal(int|float|string|null $value, int $scale[, string $decimalSeparator = ',' ]) : string|null

Non-numeric input is passed through as is; turning it into "0" would pretend the line charges nothing.

Parameters
$value : int|float|string|null
$scale : int
$decimalSeparator : string = ','
Return values
string|null

quantity()

Formats a quantity: whole without decimals, a decimal without trailing zeros; `null` stays `null` (a missing shipper or payment line), a non-numeric value passes unchanged.

public static quantity(int|float|string|null $quantity[, string $decimalSeparator = ',' ]) : string|null
Parameters
$quantity : int|float|string|null
$decimalSeparator : string = ','
Return values
string|null
On this page

Search results