Skip to main content

Class: UnitsHelper

Class to help with units formatting.

Table of contents

Properties

Methods

Constructors

Properties

MAGNITUDE_MAP

Static Readonly MAGNITUDE_MAP: Object

Map units.

Methods

formatBest

Static formatBest(value, decimalPlaces?): string

Format the value in the best units.

Parameters

NameTypeDefault valueDescription
valuenumberundefinedThe value to format.
decimalPlacesnumber2The number of decimal places to display.

Returns

string

The formated value.


formatUnits

Static formatUnits(value, magnitude, decimalPlaces?): string

Format the value in the best units.

Parameters

NameTypeDefault valueDescription
valuenumberundefinedThe value to format.
magnitudeMagnitudesundefinedThe magnitude to format with.
decimalPlacesnumber2The number of decimal places to display.

Returns

string

The formated value.


calculateBest

Static calculateBest(value): Magnitudes

Format the value in the best units.

Parameters

NameTypeDescription
valuenumberThe value to format.

Returns

Magnitudes

The best units for the value.


convertUnits

Static convertUnits(value, from, to): number

Convert the value to different units.

Parameters

NameTypeDescription
valuenumberThe value to convert.
fromMagnitudesThe from magnitude.
toMagnitudesThe to magnitude.

Returns

number

The formatted unit.

Constructors

constructor

new UnitsHelper()