FormatNumber

Formats a number with specified precision.

Syntax

FormatNumber(value: number, digits = 8): string

Parameters

  • value: number - The number to format

  • digits: number - The number of decimal places or exponent digits (-16 to 16)

Return Value

Returns a string representing the formatted number.

Description

The FormatNumber method formats a number with specified precision. It handles both regular decimal notation and scientific notation based on the value and digits parameter:

  • For digits >= 0 and <= 16:

    • Uses fixed-point notation for normal numbers

    • Uses scientific notation for very small numbers (abs < 1e-6)

  • For digits >= -16 and <= -1:

    • Uses scientific notation with abs(digits) decimal places

  • For digits outside these ranges:

    • Defaults to 8 decimal places

Example

Last updated