Toolbox-XToolbox-X

Convert to Decimal

Rounds a number to a specified number of decimal places and returns it as a number or string.

convertToDecimal

The convertToDecimal function rounds a number to a specified number of decimal places and returns it as either a number or string, based on the provided options.

Function Signature

function convertToDecimal<T extends boolean>(input: Numeric, options?: DecimalOptions<T>): ConvertedDecimal<T>

Parameters

  • input (Numeric): A number or a numeric string that needs to be rounded.
  • options (DecimalOptions<T>, optional): Configuration object to customize the rounding behavior.
    • decimalPlaces (optional): The number of decimal places to round to. Defaults to 2.
    • isString (optional): If set to true, the result will be returned as a string. Defaults to false, which returns the result as a number.

Return Value

  • Returns the input number rounded to the specified decimal places.
  • The type of the return value depends on the isString option:
    • If isString is false (default), the result is returned as a number.
    • If isString is true, the result is returned as a string.

Example Usage

playground.ts

Aliases

  • convertToFixed

Last updated: Tue, Jun 16, 2026 08:16:20PM (UTC)

On this page