Caplin Trader 5.1.0

Class: module:ct-element/formatter/BracketsFormatter

module:ct-element/formatter/BracketsFormatter()

new module:ct-element/formatter/BracketsFormatter()

Formats a negative number into a value with brackets.

BracketsFormatter is typically used in the XML Renderer Framework, but can be invoked programmatically as in the following example which evaluates to "(123)":

BracketsFormatter.format(-123, {})

See module:ct-element/parser/BracketsParser for the complementary parser.
Implements:

Methods

format(vValue, mAttributes) → {String}

Formats a negative number into a value with brackets.

Any form of suffix is assumed to be part of the number and is included in the conversion. Non-negative numeric values are unchanged.

For example, "-1.618" and "-2BIL" are converted to "(1.618)" and "(2BIL)" respectively.
Parameters:
Name Type Description
vValue String | Number

the number.

mAttributes Map

(unused)

Implements:
Returns:

if number is negative, the absolute number surrounded by brackets, otherwise the original number.

Type
String