Caplin Trader 5.1.0

Class: module:ct-element/formatter/SignificantFiguresFormatter

module:ct-element/formatter/SignificantFiguresFormatter()

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

Formats a number to the specified number of significant figures.

SignificantFiguresFormatter is typically used in the XML Renderer Framework, but can be invoked programmatically as in the following example which evaluates to '3.142':

SignificantFiguresFormatter.format(3.14159, {sf:4})
Implements:

Methods

format(vValue, mAttributes) → {String}

Formats a number to the specified number of significant figures.

Parameters:
Name Type Description
vValue String | Number

the number.

mAttributes Map

the map of attributes.

Properties
Name Type Attributes Description
sf int <optional>

the number of significant figures to apply (does nothing if omitted).

Implements:
Returns:

the number, formatted to the specified precision.

Type
String