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
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.

🌐
Mikemcl
mikemcl.github.io › decimal.js
decimal.js API
Returns a new Decimal whose value is the square root of the sum of the squares of the arguments, rounded to precision significant digits using rounding mode rounding.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › round
Math.round() - JavaScript | MDN
If the fractional portion of the argument is greater than 0.5, the argument is rounded to the integer with the next higher absolute value. If it is less than 0.5, the argument is rounded to the integer with the lower absolute value.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
However, choosing a digits precision that's too high can return unexpected results, because decimal fractional numbers cannot be represented precisely in floating point. For example: ... const numObj = 12345.6789; numObj.toFixed(); // '12346'; rounding, no fractional part numObj.toFixed(1); // '12345.7'; it rounds up numObj.toFixed(6); // '12345.678900'; additional zeros (1.23e20).toFixed(2); // '123000000000000000000.00' (1.23e-10).toFixed(2); // '0.00' (2.34).toFixed(1); // '2.3' (2.35).toFixed(1); // '2.4'; it rounds up (2.55).toFixed(1); // '2.5' // it rounds down as it can't be represented exactly by a float and the // closest representable float is lower (2.449999999999999999).toFixed(1); // '2.5' // it rounds up as it's less than Number.EPSILON away from 2.45.
🌐
CodeParrot
codeparrot.ai › blogs › javascript-round-to-2-decimal-places-a-complete-guide
JavaScript Round to 2 Decimal Places: A Complete Guide
When we discuss JavaScript Round to 2 Decimal Places, it’s because two decimal places are standard in scenarios like currency calculations. Precision beyond two decimals is unnecessary and might introduce rounding errors or inconsistencies. For instance, prices are usually displayed as $10.99 instead of $10.9876.
🌐
CoreUI
coreui.io › blog › how-to-round-a-number-to-two-decimal-places-in-javascript
How to round a number to two decimal places in JavaScript · CoreUI
February 21, 2024 - Among these, rounding to two decimal places is particularly relevant across financial calculations, statistical reporting, and data presentation for its balance between precision and readability. This comprehensive guide will walk you through the intricacies of rounding numbers to two decimal places in JavaScript, ensuring you confidently apply this operation. Table of Contents · Angular · Bootstrap · React.js ·
🌐
Zipy
zipy.ai › blog › how-to-round-to-at-most-two-decimal-places-in-javascript
how to round to at most two decimal places in javascript
April 12, 2024 - The most straightforward approach to round a number to two decimal places in JavaScript is using the toFixed() method.
🌐
Ihechikara
ihechikara.com › posts › how-to-round-a-number-in-js
How To Round Numbers in JavaScript – Explained With Code Examples
In the example above, we created a variable called num with a value of 2.5. Using the Math.round() method, we rounded the number to the closest integer, which is 3. If the digit after the decimal point is greater than or equal to 5, then the ...
Find elsewhere
🌐
Roblog
robiul.dev › round-to-2-decimal-places-in-javascript
How to Round a Number to 2 Decimal Places in JavaScript
May 28, 2023 - A Comprehensive Guide to Efficiently Round a Number to 2 decimal places in JavaScript ... 🕵🏻 Professional Web Developer ✍ Technical Writer • 👨‍💻 Making Web Development easier for beginners • ⚡ JavaScript & Node js
🌐
Favtutor
favtutor.com › articles › round-to-two-decimal-places-javascript
Round to 2 Decimal Places in JavaScript (with code)
December 14, 2023 - The toFixed() method is a built-in JavaScript function that allows us to round numbers to a specified number of decimal places. It can be applied to the numbers, and it returns the rounded number in the form of a string.
🌐
Sentry
sentry.io › sentry answers › javascript › how to round to at most two decimal places in javascript
How to round to at most two decimal places in JavaScript | Sentry
You can use it along with some arithmetic to round a number to a specific number of decimal places. To round a number to two decimal places at most, multiply the number by 10 to the power of 2. This moves the decimal place to the position where ...
🌐
Jacklmoore
jacklmoore.com › notes › rounding-in-javascript
Rounding Decimals in JavaScript
The most common solutions for rounding to a decimal place is to either use Number.prototype.toFixed(), or multiply the float by some power of 10 in order to leverage Math.round().
🌐
Codedamn
codedamn.com › news › javascript
JavaScript round a number to 2 decimal places (with examples)
December 11, 2022 - What do you understand with the question that “Round a number to x decimal places?” The answer is just round off the given decimal number to x decimal places. for example, round the 5.678 to 2 decimal places. the result will be 5.68.
🌐
Peterlunch
peterlunch.com › snippets › javascript-round
How to round to decimal places in JavaScript?
June 12, 2021 - In the example above, we take the number 123.4567 and multiply it by 100 inside of the brackets. Then we divide that by 100 to give you a lovely number rounded to 2 decimal places all thanks to JavaScript and some basic math.
🌐
Medium
medium.com › @borisdedejski › rounding-numbers-on-x-decimal-places-in-javascript-5a4bc26e4149
Rounding numbers on X decimal places in Javascript | by Boris Dedejski | Medium
September 12, 2021 - Rounding numbers on X decimal places in Javascript Rounding decimal numbers in javascript is pretty straightforward, you can just easily use the Math.round or Math.ceiland your problem is solved …
🌐
npm
npmjs.com › package › decimal.js
decimal.js - npm
For advanced usage, multiple Decimal constructors can be created, each with their own independent configuration which applies to all Decimal numbers created from it. // Set the precision and rounding of the default Decimal constructor Decimal.set({ precision: 5, rounding: 4 }) // Create another Decimal constructor, optionally passing in a configuration object Dec = Decimal.clone({ precision: 9, rounding: 1 }) x = new Decimal(5) y = new Dec(5) x.div(3) // '1.6667' y.div(3) // '1.66666666'
      » npm install decimal.js
    
Published   Jul 06, 2025
Version   10.6.0
Author   Michael Mclaughlin
🌐
Medium
medium.com › @ryan_forrester_ › how-to-round-to-2-decimal-places-in-javascript-053a869b2ce8
How to Round to 2 Decimal Places in JavaScript | by ryan | Medium
September 17, 2024 - This article explores various techniques to round numbers to 2 decimal places in JavaScript and provide practical examples.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › round-off-a-number-upto-2-decimal-place-using-javascript
Round off a number upto 2 decimal place using JavaScript - GeeksforGeeks
January 20, 2020 - The Math.round() method is applied on this number and the final result is divided by 100. This moves the decimal point back to its place as before. This number is the final rounded off number.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
According to the documentation Math.round and toFixed both round to the nearest number: 0..4 lead down while 5..9 lead up. ... Internally the decimal fraction 6.35 is an endless binary.