Unit of Measurement Formatter
The unit
formatter takes as a first parameter the unit of measurement value as a string or
number.
The second parameter is a string that represents the unit of measurement's type according to CLDR, and
the third parameter is an object which defines the format options.
The fourth optional parameter is a string representing a custom locale code. If no locale is given the
current user locale is used.
The options
and locale
parameters are optional and can be omitted. If only
options
is omitted
the locale
will be shifted in its place.
format.unit(amount, type, options?, locale?)
Param | Type | Required | Description | Since |
---|---|---|---|---|
amount | string|number | Yes | Any valid string or number representing the value of the unit to be formatted. | 1.74 |
type | string | Yes | A string that represents the unit of measurement type. Allowed values are the default units defined in the CLDR. For more details read about Unit Formatting. | 1.74 |
options | object | No | Formatting options. | 1.74 |
locale | string | No | A string representing the locale code | 1.74 |
Returns | ||||
string | The formatted unit of measurement. | 1.74 |
Examples
A card with a unit
formatter using expression binding for 'length-kilometer' with
{decimals:2, style:'short'}
as format options
"sap.card": { "type": "List", "header": { "title": "Order status", "subTitle": "Orders exceeding {= format.unit(123.456, 'length-kilometer', {decimals:2, style:'short'})} are highlighted" } }Try it Out