Use Math.round() :

Math.round(num * 100) / 100

Or to be more specific and to ensure things like 1.005 round correctly, use Number.EPSILON :

Math.round((num + Number.EPSILON) * 100) / 100
Answer from Brian Ustas on Stack Overflow
🌐
Medium
medium.com › @python-javascript-php-html-css › javascript-rounding-numbers-to-a-maximum-of-two-decimal-places-775b9650d6fb
JavaScript Rounding Numbers to a Maximum of Two Decimal Places
September 29, 2024 - Yes, the same rounding functions can be used in both frontend and backend JavaScript environments. ... You can use the Math.round() function to round a number to the nearest integer.
Discussions

javascript - How to round to at most 2 decimal places, if necessary - Stack Overflow
Performance should be a concern also, which could make this approach less desirable. Math.round() is much faster. jsbin.com/kikocecemu/edit?js,output 2021-09-28T16:51:12.21Z+00:00 ... Note: "Executing JavaScript from a string is an enormous security risk. More on stackoverflow.com
🌐 stackoverflow.com
Why not always use Math.round instead of Math.floor?

Well, they are two different functions, with two different uses. Math.floor() always rounds down to the nearest integer, while Math.round() will round up or down depending on what side of .5 the number falls on. So, the basic answer is that you use which one gets the result you expect.

When it comes to generating random numbers though, Math.floor() has a more even distribution than Math.round(). If you want to generate a random number between 0 and 2, take the following examples:

Math.floor(Math.random() * 3). Here, 0-0.999999 will give you 0, 1.0 to 1.999999 will give you 1, and 2.0 to 2.999999 will give you 2. Every number has a 33% chance of being the result.

Math.round(Math.random() * 2). Here, 0-0.499999 will give you 0, 0.5 to 1.499999 will give you 1, and 1.5 to 1.999999 will give you 2. Note that the range of numbers that lead to a 1 is twice as big as those that lead to 0 or 1. That is 25% chance of 0, 50% chance of 1, and 25% chance of 2.

More on reddit.com
🌐 r/javascript
13
1
January 8, 2016
what is the difference between using math.ceil and round for rounding the decimal ?
ceil always rounds up. More on reddit.com
🌐 r/learnpython
3
2
October 10, 2022
how to round to 2 decimal places with typescript?
It's not a typescript question, it's a javascript question (maybe even just a math question). But what you are looking for is the toFixed() method. (5).toFixed(2) // returns the string "5.00" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed btw : your first example "123.45 => should return 123.46" there should be no rounding here it should return "123.45", and toFixed() will take care of rounding for you. More on reddit.com
🌐 r/typescript
9
1
December 25, 2019
🌐
WeWeb Community
community.weweb.io › ask us anything › how do i?
Math formula to round numbers to ceiling - How do I? - WeWeb Community
March 11, 2023 - HI, so i need to round numbers up to the nearest full integer. So for instance if my number is 1.2 it has to round up to 2. But i noticed that with the “round” formula it rounds down to the nearest integer which would be…
🌐
TutorialsPoint
tutorialspoint.com › article › How-to-round-up-a-number-in-JavaScript
How to round up a number in JavaScript?
In the above example, we have applied the Math.floor() property to three different variables x, y, and, z. First, we create the variable ?x? it is an integer so when we apply the Math.floor property to it and assign that value to variable ?value1? ...
🌐
W3Schools
w3schools.com › jsref › jsref_round.asp
JavaScript Math round() Method
The Math.round() method rounds a number to the nearest integer.
🌐
Can I Use
caniuse.com › mdn-javascript_builtins_math_round
JavaScript built-in: Math: round | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Find elsewhere
Top answer
1 of 16
5568

Use Math.round() :

Math.round(num * 100) / 100

Or to be more specific and to ensure things like 1.005 round correctly, use Number.EPSILON :

Math.round((num + Number.EPSILON) * 100) / 100
2 of 16
4380

If the value is a text type:

parseFloat("123.456").toFixed(2);

If the value is a number:

var numb = 123.23454;
numb = numb.toFixed(2);

There is a downside that values like 1.5 will give "1.50" as the output. A fix suggested by @minitech:

var numb = 1.5;
numb = +numb.toFixed(2);
// Note the plus sign that drops any "extra" zeroes at the end.
// It changes the result (which is a string) into a number again (think "0 + foo"),
// which means that it uses only as many digits as necessary.

It seems like Math.round is a better solution. But it is not! In some cases it will not round correctly:

Math.round(1.005 * 100)/100 // Returns 1 instead of expected 1.01!

toFixed() will also not round correctly in some cases (tested in Chrome v.55.0.2883.87)!

Examples:

parseFloat("1.555").toFixed(2); // Returns 1.55 instead of 1.56.
parseFloat("1.5550").toFixed(2); // Returns 1.55 instead of 1.56.
// However, it will return correct result if you round 1.5551.
parseFloat("1.5551").toFixed(2); // Returns 1.56 as expected.

1.3555.toFixed(3) // Returns 1.355 instead of expected 1.356.
// However, it will return correct result if you round 1.35551.
1.35551.toFixed(2); // Returns 1.36 as expected.

I guess, this is because 1.555 is actually something like float 1.55499994 behind the scenes.

Solution 1 is to use a script with required rounding algorithm, for example:

function roundNumber(num, scale) {
  if(!("" + num).includes("e")) {
    return +(Math.round(num + "e+" + scale)  + "e-" + scale);
  } else {
    var arr = ("" + num).split("e");
    var sig = ""
    if(+arr[1] + scale > 0) {
      sig = "+";
    }
    return +(Math.round(+arr[0] + "e" + sig + (+arr[1] + scale)) + "e-" + scale);
  }
}

It is also at Plunker.

Note: This is not a universal solution for everyone. There are several different rounding algorithms. Your implementation can be different, and it depends on your requirements. See also Rounding.

Solution 2 is to avoid front end calculations and pull rounded values from the backend server.

Another possible solution, which is not a bulletproof either.

Math.round((num + Number.EPSILON) * 100) / 100

In some cases, when you round a number like 1.3549999999999998, it will return an incorrect result. It should be 1.35, but the result is 1.36.

🌐
JavaScripter
javascripter.net › faq › rounding.htm
Rounding in JavaScript
Math.round(X); // round X to an integer Math.round(10*X)/10; // round X to tenths Math.round(100*X)/100; // round X to hundredths Math.round(1000*X)/1000; // round X to thousandths ...
🌐
Code.mu
code.mu › en › javascript › manual › math › Math.round
The Math.round method - a number rounding in JavaScript
The round method of the Math object rounds to the nearest whole number using the rules of mathematical rounding in JavaScript.
🌐
Math.js
mathjs.org › docs › reference › functions › round.html
math.js | an extensive math library for JavaScript and Node.js
Round a value towards the nearest rounded value. For matrices, the function is evaluated element wise. math.round(x) math.round(x, n) math.round(unit, valuelessUnit) math.round(unit, n, valuelessUnit) Type | Description —- | ———– ·
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › round() in javascript
round() in JavaScript | Examples of round() in JavaScript
March 2, 2023 - This function is used to round off the number to the nearest integer. The concept of rounding off the number is if the fractional part of the number is greater than or equal to 0.5, then the number will be rounded off to the next higher integer.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
SheCodes
shecodes.io › athena › 109834-how-to-use-math-round-in-a-javascript-function
[JavaScript] - How to use Math.round() in a JavaScript | SheCodes
Learn how to use the Math.round() function in JavaScript to round a number to the nearest whole number in a function.
🌐
CoreUI
coreui.io › answers › how-to-round-a-number-in-javascript
How to round a number in JavaScript · CoreUI
September 26, 2025 - The Math.round() function rounds a number to the nearest integer using standard mathematical rounding (0.5 rounds up). In the first example, Math.round(3.7456) returns 4 because 3.7456 is closer to 4 than to 3. For decimal precision, multiply ...
🌐
Robin Wieruch
robinwieruch.de › javascript-rounding-errors
JavaScript Rounding Errors (in Financial Applications)
The Math.round() function rounds a number to the nearest integer which you usually want when working with financial applications where you want to keep monetary values as integers (read: cents).
🌐
Way2tutorial
way2tutorial.com › javascript › example › round_function.php
JavaScript Math.Round() function
Are you trying to build your own website, but not sure where to start? With our interactive web development tutorials learn the basic steps in order to become a web developer.
🌐
Stack Abuse
stackabuse.com › rounding-numbers-in-javascript-using-ceil-floor-and-round
Rounding Numbers in JavaScript using ceil(), floor() and round()
October 17, 2021 - let x = 4.7 console.log(Math.round(x)) // Output: 5 let y = 4.2 console.log(Math.round(y)) // Output: 4 let z = 4.5 console.log(Math.round(z)) // Output: 5 console.log(Math.round(null)) // Output: 0 · Everything up to x.49 will be rounded down to the lower value, while everything higher than that will be rounded to the higher value. In this quick article, we had a look at some of the methods that can be used to round a non-integer in JavaScript.
🌐
SitePoint
sitepoint.com › blog › javascript › a guide to rounding numbers in javascript
A Guide to Rounding Numbers in JavaScript — SitePoint
November 13, 2024 - We can use Math.fround to see how it’s actually represented: ... As you can see, it’s actually represented by the floating point number 3.549999952316284, which rounds down to 3.5. These problems with rounding numbers in JavaScript don’t occur too often, but they’re definitely something you should be aware of if you’re doing a lot of rounding — especially when it’s important that the result is accurate.
🌐
VR Soft Tech
vrsofttech.com › javascript › javascript-math-round
JavaScript Math.round() | vrsofttech
Number - The value of x rounded to the nearest integer. ... console.log(Math.round(10.5)); //11 console.log(Math.round(10.2)); //10 console.log(Math.round(10.7)); //11 console.log(Math.round(-10.5)); //-10 console.log(Math.round(-10.2)); //-10 console.log(Math.round(-10.7)); //-11 Try it Yourself
🌐
Career Karma
careerkarma.com › blog › javascript › javascript math object: round
JavaScript Math Object: Round | Career Karma
December 29, 2020 - This article will show you how to use the Math Object to figure out how a floating point number rounds to the nearest integer.