Caplin Trader 4.8.0

Class: module:caplin/element/formatter/SignificantFiguresFormatter

module:caplin/element/formatter/SignificantFiguresFormatter

Constructor

new module:caplin/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':

caplin.element.formatter.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).
Returns:
the number, formatted to the specified precision.
Type
String