Number.toFixed

toFixed — Returns a string representation of the specified Number object.

Description

Number.toFixed([integer decimals])

Parameters

Name Description Type Default Optional
decimals A number between 0 and 20 representing number of digits. integer 0 Yes

Examples

Example #1 – toFixed example
var n = new Number(42.12345); console.log(n.toFixed()); // Will be the primitive string "42". console.log(n.toFixed(2)); // Will be the primitive string "42.12". console.log(n.toFixed(4)); // Will be the primitive string "42.1235". console.log(n.toFixed(6)); // Will be the primitive string "42.123450".

External references