Toolbox-XToolbox-X

Instance Methods

Instance methods for the Unit class including string representation, prefix conversion, and generic unit conversion.

toString()

toString(): string

Returns a formatted "value unit" string. Omits unit if not provided in constructor.

playground.ts

convertByPrefix()

convertByPrefix(fromPrefix: SIPrefix, toPrefix: SIPrefix): number

Parameters

ParameterTypeDescription
fromPrefixSIPrefixSource SI prefix (e.g., 'k', 'm').
toPrefixSIPrefixTarget SI prefix (e.g., 'M', '').

Returns

  • number: Converted value.
playground.ts

convertFromTo()

convertFromTo(from: string, to: string): number

Parameters

ParameterTypeDescription
fromstringSource unit with prefix (e.g., 'kg', 'cm').
tostringTarget unit with prefix (e.g., 'g', 'm').

Returns

  • number: Converted value. Units must be of same type (e.g., both length).
playground.ts

convert()

convert(methodName: UnitNumberMethods): number

Parameters

ParameterTypeDescription
methodNameUnitNumberMethodsName of static conversion method.

Returns

  • number: Converted value with type-safe method selection.
playground.ts

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page