Using Math.floor() is one way of doing this.

More information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor

Answer from phoebus on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_round.asp
JavaScript Math round() Method
❮ Previous JavaScript Math Object ... let e = Math.round(-2.50); let f = Math.round(-2.49); Try it Yourself » · The Math.round() method rounds a number to the nearest integer....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › round
Math.round() - JavaScript | MDN
Math.round(-Infinity); // -Infinity Math.round(-20.51); // -21 Math.round(-20.5); // -20 Math.round(-0.1); // -0 Math.round(0); // 0 Math.round(20.49); // 20 Math.round(20.5); // 21 Math.round(42); // 42 Math.round(Infinity); // Infinity
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › floor
Math.floor() - JavaScript | MDN
In this example, we implement a method called decimalAdjust() that is an enhancement method of Math.floor(), Math.ceil(), and Math.round(). While the three Math functions always adjust the input to the units digit, decimalAdjust accepts an exp parameter that specifies the number of digits to the left of the decimal point to which the number should be adjusted.
🌐
pawelgrzybek
pawelgrzybek.com › rounding-and-truncating-numbers-in-javascript
Rounding and truncating numbers in JavaScript | pawelgrzybek.com
JavaScript uses three methods to achieve this: Math.round() - rounds to the nearest integer (if the fraction is 0.5 or greater - rounds up) Math.floor() - rounds down · Math.ceil() - rounds up · Math.round(3.14159) // 3 Math.round(3.5) // ...
🌐
Ihechikara
ihechikara.com › posts › how-to-round-a-number-in-js
How To Round Numbers in JavaScript – Explained With Code Examples
The Math.floor() method rounds a number down irrespective of the value of the digit that comes after the decimal point. So the number will be rounded down whether the digit after the decimal point is greater than, equal to, or less than 5. In ...
🌐
SitePoint
sitepoint.com › blog › javascript › a guide to rounding numbers in javascript
A Guide to Rounding Numbers in JavaScript — SitePoint
November 13, 2024 - For instance, Math.floor rounds a negative number down to the next lowest integer, while Math.trunc truncates the decimal part, effectively rounding it up. Precision issues can occur in JavaScript due to the binary representation of numbers. Some base 10 numbers can’t be accurately represented in base 2, causing rounding errors.
🌐
Codedamn
codedamn.com › news › javascript
JavaScript round a number to 2 decimal places (with examples)
December 11, 2022 - let temp = Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", maximumSignificantDigits: 2, }); console.log(temp.format(1144.2945)); console.log(temp.format(114425)); console.log(temp.format(134.22)); Code language: JavaScript (javascript) ... These are functions defined by the users themselves. here I have shown some examples below: Example of a user-defined function by using an exponent. It will round the number up and down.
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › jsref_floor.asp
JavaScript Math floor() Method
The Math.floor() method rounds a number DOWN to the nearest integer. The Math.abs() Method The Math.ceil() Method The Math.floor() Method The Math.round() Method The Math.fround() Method The Math.f16round() Method The Math.trunc() Method ...
🌐
Altcademy
altcademy.com › blog › how-to-round-a-number-in-javascript
How to round a number in JavaScript
June 9, 2023 - Now that we've covered the various ... one. Use Math.round() when you want to round a number to the nearest whole number, following the standard rounding rules (0.5 and above rounds up, while below 0.5 rounds down)...
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.

🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
That happens because Math.round() gets random numbers from the interval 1..3 and rounds them as follows: values from 1 ... to 1.4999999999 become 1 values from 1.5 ... to 2.4999999999 become 2 values from 2.5 ...
🌐
Oreate AI
oreateai.com › blog › javascript-how-to-round-a-number › 7427637accf913cf476061ad7d360aaa
Javascript How to Round a Number - Oreate AI Blog
January 7, 2026 - var num = 2.446242342; um = Math.round((num + Number.EPSILON) * 100) / 100; // Outputs '2.45' By adding a tiny value (Number.EPSILON), we ensure our rounding behaves as expected without introducing significant errors. For those moments when you want complete control over whether you're rounding up or down regardless of decimal values, consider using Math.floor() and Math.ceil().
🌐
javaspring
javaspring.net › blog › javascript-math-round-to-two-decimal-places
How to Round to Two Decimal Places in JavaScript Using Math.round (Instead of Whole Number) — javaspring.net
To counteract floating-point errors, add a tiny value (e.g., 1e-8 or Number.EPSILON) to the scaled number before rounding. This pushes the value just above the threshold for correct rounding. ... const originalNumber = 0.295; const scaled = originalNumber * 100 + Number.EPSILON; // 29.499999999999996 + 2.220446049250313e-16 ≈ 29.5 const rounded = Math.round(scaled) / 100; console.log(rounded); // 0.30 (correct!) If the result is an integer (e.g., 2.00), JavaScript may display it as 2 instead of 2.00.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
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.
🌐
TutorialsPoint
tutorialspoint.com › how-can-i-round-down-a-number-in-javascript
How can I round down a number in JavaScript?
Users can observe that we can round down positive numbers by removing the decimal part and round down negative numbers by removing the decimal part and subtracting 1 from the output. We will use the modulo operator in this approach to overcome our problem. When we take a modulo of any float ...
🌐
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 - let number = 2.123456; let rounded = Math.floor(number * 100) / 100; console.log(rounded); // Output: 2.12 ... Returns a number, avoiding the need for type conversion. More control over the direction of rounding.
🌐
CodeParrot
codeparrot.ai › blogs › javascript-round-to-2-decimal-places-a-complete-guide
JavaScript Round to 2 Decimal Places: A Complete Guide
Precision is crucial in JavaScript, and mastering JavaScript Round to 2 Decimal Places is essential for accurate calculations and clean formatting. In this blog, we’ll explore methods like Math.round and Math.floor in JavaScript. As a bonus, we’ll also discuss how to round numbers to the nth decimal place for advanced scenarios!