Number.prototype.toFixed is a function designed to format a number before printing it out. It's from the family of toString, toExponential and toPrecision.

To round a number, you would do this:

someNumber = 42.008;
someNumber = Math.round( someNumber * 1e2 ) / 1e2;
someNumber === 42.01;

// if you need 3 digits, replace 1e2 with 1e3 etc.
// or just copypaste this function to your code:

function toFixedNumber(num, digits, base){
  const pow = Math.pow(base ?? 10, digits);
  return Math.round(num*pow) / pow;
}

Why isn't this function included in the JavaScript's standard library? Because floating point numbers are hard! Many decimal numbers cannot be directly represented by base-two floats – that's why 0.09 + 0.01 !== 0.1 but 0.09999999999999999. If developers were given a tool which is supposed to round floats to decimal places, they'd (wrongly) assume that it really returns a decimal number, when it in fact returns the closest representable double-precision base-two float.

Answer from a pfp with melon on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
The toFixed() method of Number values returns a string representing this number using fixed-point notation with the specified number of decimal places.
🌐
W3Schools
w3schools.com › jsref › jsref_tofixed.asp
JavaScript toFixed() Method
The toFixed() method rounds the string to a specified number of decimals.
Discussions

types - How can I round a number in JavaScript? .toFixed() returns a string? - Stack Overflow
Your answer is slightly misleading: toFixed is a formatting function, which has a sole purpose of converting a number to a string, formatting it using the specified number of decimals. The reason it returns a string is because it's supposed to return a string, and if it was named toStringFixed ... More on stackoverflow.com
🌐 stackoverflow.com
This is why you should not using "toFixed" to rounding a number to the nearest integer.
You shouldn’t really be using toFixed to round a number because It converts the number to a string. Anyway, this is a good read https://stackoverflow.com/questions/10015027/javascript-tofixed-not-rounding More on reddit.com
🌐 r/JavaScriptTips
4
11
November 1, 2022
Javascript toFixed function - Stack Overflow
Note that the toFixed method of the JavaScript's Number object actually returns a String. The above toFixed function will return a Number. More on stackoverflow.com
🌐 stackoverflow.com
javascript - Using toFixed(2) and math round to get correct rounding - Stack Overflow
I would like to find a function that will return this kind of formatted values : 1.5555 => 1.55 1.5556 => 1.56 1.5554 => 1.55 1.5651 => 1.56 toFixed() and math round return this value ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
gist.github.com › dfkaye › e977af36e668aa134c0ce55bab5bb15f
[ work in progress ] Test & polyfill-fix for JavaScript Number.toFixed() bugs; e.g., (1.015).toFixed(2) returns "1.01" instead of "1.02" · GitHub
That means there's a simple fix for all implementations of toFixed(): If the value contains a decimal, append "1" to the end of the string version of the value to be modified.
🌐
Sanori's Blog
sanori.github.io › 2019 › 04 › JavaScript-Pitfalls-Tips-toFixed
JavaScript Pitfalls & Tips: toFixed | Sanori's Blog
April 28, 2019 - If you need to calculate more precisely than 64-bit floating points notation, you would better use one of the arbitrary precision libraries. Most arbitrary precision libraries can designate precision in decimal places. Moreover, most of the libraries support toFixed.
Find elsewhere
🌐
YouTube
youtube.com › watch
How to Format Numbers with toFixed() and parseFloat() in JavaScript | Round and Convert Values in JS - YouTube
Want to format numbers in JavaScript to 2 decimal places or convert strings to numbers? In this beginner-friendly tutorial, you’ll learn how to use toFixed()...
Published: July 6, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › typescript-tofixed-function
TypeScript toFixed() Function - GeeksforGeeks
July 19, 2024 - Javascript · OOP · DOM · Object · Operators · Union Types · Last Updated : 19 Jul, 2024 · The toFixed() function in TypeScript formats a number using fixed-point notation, specifying the number of digits after the decimal point.
🌐
SitePoint
sitepoint.com › blog › javascript › number().tofixed() rounding errors: broken but fixable
Number().toFixed() Rounding Errors: Broken But Fixable — SitePoint
November 6, 2024 - The fixed (number of digits) argument to toFixed() is calculated from the length of the fraction value.
🌐
Bennadel
bennadel.com › blog › 1013-javascript-number-tofixed-method.htm
Javascript Number.toFixed() Method
April 19, 2020 - While reading the book, Learning ... which can only be called on numeric values, will return a string representation of the number with the given number of decimal places....
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_tofixed.asp.html
JavaScript toFixed() Method
JavaScript Number Reference · ... Try it Yourself » · More "Try it Yourself" examples below. The toFixed() method converts a number into a string, keeping a specified number of decimals....
🌐
Medium
dilanivasanthan26.medium.com › different-betwwen-tofixed-toprecision-and-mathround-20ed8edaf78a
Different between toFixed, toPrecision and mathRound | by Dilani Vasanthan | Medium
October 12, 2023 - - `toFixed()` is a method that can be called on a number in JavaScript. - It formats a number to a specified number of decimal places and returns a string. - The specified argument indicates the number of decimal places in the result.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-tofixed-and-toprecision-in-javascript
Difference Between toFixed() and toPrecision() in JavaScript - GeeksforGeeks
August 5, 2025 - Example: toFixed(2) rounds num ... toPrecision() method in JavaScript returns a string representing the number in the exponential or fixed-point notation depending on the input precision....
🌐
TutorialsPoint
tutorialspoint.com › javascript › number_tofixed.htm
JavaScript Number toFixed() Method
The JavaScript Number toFixed() method returns the representation of a numerical value with or without decimal places. It includes an optional parameter called 'digits'. However, if the digits parameter is not within the range of '[0,100]', ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number
Number - JavaScript | MDN
Number.prototype.toFixed() Returns a string representing the number in fixed-point notation. Number.prototype.toLocaleString() Returns a string with a language sensitive representation of this number. Overrides the Object.prototype.toLocaleString() method. Number.prototype.toPrecision() Returns ...
🌐
SheCodes
shecodes.io › athena › 287246-explaining-the-tofixed-method-in-javascript
Explaining the toFixed() Method in JavaScript
Learn how to use the toFixed() method in JavaScript to format numbers with a specified number of decimal places.
🌐
SitePoint
sitepoint.com › javascript
Number toFixed(2) in Js if decimal have - JavaScript - SitePoint Forums | Web Development & Design Community
September 19, 2022 - Hi @wawane7256, note that toFixed() is a formatting method and returns a string not a number; if this is what you want, you might use a regular expression to remove the .00 suffix: