(Math.round(num * 100) / 100).toFixed(2);

Live Demo

var num1 = "1";
document.getElementById('num1').innerHTML = (Math.round(num1 * 100) / 100).toFixed(2);

var num2 = "1.341";
document.getElementById('num2').innerHTML = (Math.round(num2 * 100) / 100).toFixed(2);

var num3 = "1.345";
document.getElementById('num3').innerHTML = (Math.round(num3 * 100) / 100).toFixed(2);
span {
    border: 1px solid #000;
    margin: 5px;
    padding: 5px;
}
<span id="num1"></span>
<span id="num2"></span>
<span id="num3"></span>

Note that it will round to 2 decimal places, so the input 1.346 will return 1.35.

Answer from jrn.ak on Stack Overflow
🌐
W3Schools
w3schools.com › howto › howto_js_format_number_dec.asp
How To Format a Number with Two Decimals
You can use the toFixed() method to format a number to only show two decimals. Note that the result is rounded (shows 5.57 instead of 5.56): let num = 5.56789; let n = num.toFixed(2); // 5.57 Try it Yourself » · If you want to display three ...
🌐
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. function financial(x) { return Number.parseFloat(x).toFixed(2); } console.log(financial(123.456)); // Expected output: "123.46" console.lo...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-a-number-with-two-decimals-in-javascript
How to Format a Number with Two Decimals in JavaScript? - GeeksforGeeks
July 23, 2025 - In this article we will explore different approaches to format a number with two decimals in JavaScript.
🌐
TutorialsPoint
tutorialspoint.com › how-to-format-a-number-with-two-decimals-in-javascript
How to format a number with two decimals in JavaScript?
The Math.floor() method returns the greatest integer less than or equal to its argument. But we can use this method to format a number with two decimals.
🌐
Attacomsian
attacomsian.com › blog › javascript-format-numbers
Format a number to 2 decimal places in JavaScript
November 27, 2022 - The toFixed() method takes a number as input, representing the number of digits to appear after the decimal point, and returns a formatted string representing the given number. const num1 = 12.865 const res1 = num1.toFixed(2) console.log(res1) ...
🌐
W3docs
w3docs.com › javascript
How to Format a Number with Two Decimals in JavaScript
There are several methods used to format a number with two decimals in JavaScript. Let’s see the difference between the methods. You can use the Intl.NumberFormat constructor. It is supported in major browsers and in Node.js: ... const formatter ...
Find elsewhere
🌐
CodeParrot
codeparrot.ai › blogs › javascript-round-to-2-decimal-places-a-complete-guide
JavaScript Round to 2 Decimal Places: A Complete Guide
Number.EPSILON accounts for minute inaccuracies in floating-point calculations, improving precision in JavaScript Round to 2 Decimal Places for tricky numbers like 1.005 or 1.255. The Intl.NumberFormat API is a versatile constructor for formatting numbers as per locale-specific conventions.
🌐
TestMu AI Community
community.testmu.ai › ask a question
JavaScript: Format Number to 2 Decimal Places - TestMu AI Community
September 11, 2024 - How can I format a number in JavaScript to always show 2 decimal places, rounding where applicable? For example, I want to achieve the following: number display 1 1.00 1.341 1.34 1.345 1.35 I’ve been using parseFloat(num).toFixed(2);, but it’s displaying 1 as 1 instead of 1.00.
🌐
W3docs
w3docs.com › javascript
How to Format Number with Two Decimals
var num1 = "1"; console.log((Math.round(num1 * 100) / 100).toFixed(2)); var num2 = "1.586"; console.log((Math.round(num2 * 100) / 100).toFixed(2)); var num3 = "1.756324"; console.log((Math.round(num3 * 100) / 100).toFixed(2)); ... However, this ...
🌐
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 - This method rounds the number and formats it according to the specified locale, making it invaluable for international applications. ... The key to rounding to 2 decimal places is to manipulate the number such that the function applies rounding at the correct decimal position, as illustrated through the methods above. How do you round numbers in JavaScript ...
🌐
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.round((number + Number.EPSILON) * 100) / 100; console.log(rounded); // Output: 2.12 · Adding Number.EPSILON ensures the rounding operation accounts for the floating-point representation, making the operation more reliable. For applications requiring high precision, external libraries like Decimal.js can be invaluable. These libraries are designed to handle decimal numbers more accurately than JavaScript's native Number type, making them ideal for financial applications, among others.
Top answer
1 of 16
1156

To format a number using fixed-point notation, you can simply use the toFixed method:

Copy(10.8).toFixed(2); // "10.80"

var num = 2.4;
alert(num.toFixed(2)); // "2.40"

Note that toFixed() returns a string.

IMPORTANT: Note that toFixed does not round 90% of the time, it will return the rounded value, but for many cases, it doesn't work.

For instance:

2.005.toFixed(2) === "2.00"

UPDATE:

Nowadays, you can use the Intl.NumberFormat constructor. It's part of the ECMAScript Internationalization API Specification (ECMA402). It has pretty good browser support, including even IE11, and it is fully supported in Node.js.

Copyconst formatter = new Intl.NumberFormat('en-US', {
   minimumFractionDigits: 2,      
   maximumFractionDigits: 2,
});

console.log(formatter.format(2.005)); // "2.01"
console.log(formatter.format(1.345)); // "1.35"
Run code snippetEdit code snippet Hide Results Copy to answer Expand

You can alternatively use the toLocaleString method, which internally will use the Intl API:

Copyconst format = (num, decimals) => num.toLocaleString('en-US', {
   minimumFractionDigits: 2,      
   maximumFractionDigits: 2,
});


console.log(format(2.005)); // "2.01"
console.log(format(1.345)); // "1.35"
Run code snippetEdit code snippet Hide Results Copy to answer Expand

This API also provides you a wide variety of options to format, like thousand separators, currency symbols, etc.

2 of 16
112

This is an old topic but still top-ranked Google results and the solutions offered share the same floating point decimals issue. Here is the (very generic) function I use, thanks to MDN:

Copyfunction round(value, exp) {
  if (typeof exp === 'undefined' || +exp === 0)
    return Math.round(value);

  value = +value;
  exp = +exp;

  if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0))
    return NaN;

  // Shift
  value = value.toString().split('e');
  value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)));

  // Shift back
  value = value.toString().split('e');
  return +(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp));
}

As we can see, we don't get these issues:

Copyround(1.275, 2);   // Returns 1.28
round(1.27499, 2); // Returns 1.27

This genericity also provides some cool stuff:

Copyround(1234.5678, -2);   // Returns 1200
round(1.2345678e+2, 2); // Returns 123.46
round("123.45");        // Returns 123

Now, to answer the OP's question, one has to type:

Copyround(10.8034, 2).toFixed(2); // Returns "10.80"
round(10.8, 2).toFixed(2);    // Returns "10.80"

Or, for a more concise, less generic function:

Copyfunction round2Fixed(value) {
  value = +value;

  if (isNaN(value))
    return NaN;

  // Shift
  value = value.toString().split('e');
  value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + 2) : 2)));

  // Shift back
  value = value.toString().split('e');
  return (+(value[0] + 'e' + (value[1] ? (+value[1] - 2) : -2))).toFixed(2);
}

You can call it with:

Copyround2Fixed(10.8034); // Returns "10.80"
round2Fixed(10.8);    // Returns "10.80"

Various examples and tests (thanks to @t-j-crowder!):

Show code snippet

Copyfunction round(value, exp) {
  if (typeof exp === 'undefined' || +exp === 0)
    return Math.round(value);

  value = +value;
  exp = +exp;

  if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0))
    return NaN;

  // Shift
  value = value.toString().split('e');
  value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)));

  // Shift back
  value = value.toString().split('e');
  return +(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp));
}
function naive(value, exp) {
  if (!exp) {
    return Math.round(value);
  }
  var pow = Math.pow(10, exp);
  return Math.round(value * pow) / pow;
}
function test(val, places) {
  subtest(val, places);
  val = typeof val === "string" ? "-" + val : -val;
  subtest(val, places);
}
function subtest(val, places) {
  var placesOrZero = places || 0;
  var naiveResult = naive(val, places);
  var roundResult = round(val, places);
  if (placesOrZero >= 0) {
    naiveResult = naiveResult.toFixed(placesOrZero);
    roundResult = roundResult.toFixed(placesOrZero);
  } else {
    naiveResult = naiveResult.toString();
    roundResult = roundResult.toString();
  }
  $("<tr>")
    .append($("<td>").text(JSON.stringify(val)))
    .append($("<td>").text(placesOrZero))
    .append($("<td>").text(naiveResult))
    .append($("<td>").text(roundResult))
    .appendTo("#results");
}
test(0.565, 2);
test(0.575, 2);
test(0.585, 2);
test(1.275, 2);
test(1.27499, 2);
test(1234.5678, -2);
test(1.2345678e+2, 2);
test("123.45");
test(10.8034, 2);
test(10.8, 2);
test(1.005, 2);
test(1.0005, 2);
Copytable {
  border-collapse: collapse;
}
table, td, th {
  border: 1px solid #ddd;
}
td, th {
  padding: 4px;
}
th {
  font-weight: normal;
  font-family: sans-serif;
}
td {
  font-family: monospace;
}
Copy<table>
  <thead>
    <tr>
      <th>Input</th>
      <th>Places</th>
      <th>Naive</th>
      <th>Thorough</th>
    </tr>
  </thead>
  <tbody id="results">
  </tbody>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
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.
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to round a number to 2 decimal places in javascript
How to Round a Number to 2 Decimal Places in JavaScript
December 11, 2022 - To round a number to 2 decimal places in JavaScript, call the toFixed() method on the number, i.e., num.toFixed(2). toFixed() will round and format the number to 2 decimal places.
🌐
W3Schools
w3schools.com › jsref › jsref_tofixed.asp
JavaScript toFixed() Method
The toFixed() method rounds the string to a specified number of decimals.
🌐
Favtutor
favtutor.com › articles › round-to-two-decimal-places-javascript
Round to 2 Decimal Places in JavaScript (with code)
December 14, 2023 - We then use the Math.round() function to round the resulting value to the nearest integer. Finally, we divide the rounded value by 100 to shift the decimal places back to their original position.
🌐
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 - Rounding numbers to a specific number of decimal places is a common requirement in JavaScript, especially for financial calculations, user input validation, and data formatting. This article explores various techniques to round numbers to 2 decimal places in JavaScript and provide practical ...
🌐
Medium
medium.com › @noffybarudwale › javascript-format-numbers-with-commas-and-decimals-86b68ec5b180
JavaScript : Format numbers with commas and decimals. | by Nofij Barudwale | Medium
October 13, 2021 - There are many different ways of printing an integer with a comma as a thousands separators in JavaScript. I found a good function that details how to and thought I would reproduce it here. It basically takes any number and turns it into formatted string with the thousands separated by commas and decimals.