Skip to content

toFixed

The toFixed() method formats a number using fixed-point notation with a specified number of decimals. It returns a string representation of the number.

Interactive example

Syntax

Classic signature

typescript
function toFixed<
	GenericInput extends number
>(
	input: GenericInput,
	digits: number
): string

Curried signature

typescript
function toFixed<
	GenericInput extends number
>(
	digits: number
): (input: GenericInput) => string

Parameters

  • input: The number to format (classic signature only).
  • digits: The number of digits after the decimal point (between 0 and 100).

Return value

returns a string representing the number with the specified number of decimals.

See also

  • round - Rounds a number to the nearest integer
  • floor - Rounds a number down
  • ceil - Rounds a number up

Sources

Released under the MIT license.