(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
🌐
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 - Below are different approaches to format a number with two decimals in JavaScript: ... In this approach we are using the toFixed() method. This method formats a number using fixed-point notation.
🌐
W3Schools
w3schools.com › jsref › jsref_tofixed.asp
JavaScript toFixed() Method
❮ Previous JavaScript Number Reference Next ❯ · let num = 5.56789; let n = num.toFixed(); Try it Yourself » · let num = 5.56789; let n = num.toFixed(2); Try it Yourself » · More examples below · The toFixed() method converts a number ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-parse-float-with-two-decimal-places-in-javascript
How to Parse Float with Two Decimal Places in JavaScript? - GeeksforGeeks
Example: In this example, the ParseFloat converts a string to a number with specified decimal places. It slices the string up to the desired decimal precision and then converts it back to a number. ... function ParseFloat(str,val) { str = str.toString(); str = str.slice(0, (str.indexOf(".")) + val + 1); return Number(str); } console.log(ParseFloat("10.547892",2)) ... JavaScript is best known for web page development but it is also used in a variety of non-browser environments.
Published   July 23, 2025
🌐
Attacomsian
attacomsian.com › blog › javascript-format-numbers
Format a number to 2 decimal places in JavaScript
November 27, 2022 - You can use the toFixed() method to format a number to 2 decimal places in JavaScript. 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 ...
🌐
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 - The toFixed() method formats a number using fixed-point notation. It returns a string representation of the number rounded to a specified number of decimal places.
🌐
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. This method converts a number into a string, rounding it to a specified number of decimal places. let number = 2.123456; let ...
Find elsewhere
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

🌐
W3Schools
w3schools.com › howto › howto_js_format_number_dec.asp
How To Format a Number with Two Decimals
let num = 5.56789; let n = ... let n = num.toFixed(3); // 5.568 Try it Yourself » · Tip: Learn more about the toFixed() method in our JavaScript Reference....
🌐
TutorialsPoint
tutorialspoint.com › How-to-format-a-number-with-two-decimals-in-JavaScript
How to format a number with two decimals in JavaScript?
Some of them are listed as follows ? ... The toFixed() method formats a number with a specific number of digits to the right of the decimal. it returns a string representation of the number that does not use exponential notation and has the exact number of digits after the decimal place.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-format-number-to-two-decimal-places
Format a number to 2 Decimal places in JavaScript | bobbyhadz
This issue is very commonly ... or 0.2. The code gets rounded to the nearest number, resulting in a rounding error. The toFixed method returns a string......
🌐
TestMu AI Community
community.testmu.ai › ask a question
JavaScript: Format Number to 2 Decimal Places - TestMu AI Community
September 6, 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.
🌐
Attacomsian
attacomsian.com › blog › javascript-parse-float-two-decimal-places
Parse float with 2 decimal places in JavaScript
November 27, 2022 - The toFixed() method takes a number as input and returns a string representation of the number formatted to 2 decimal places.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript round to 2 decimal places
How to Round a Number to 2 Decimal Places in JavaScript | Delft Stack
March 11, 2025 - The toFixed() method is one of the simplest and most straightforward ways to round a number to two decimal places in JavaScript. This method converts a number into a string representation, keeping a specified number of decimals.
🌐
Codedamn
codedamn.com › news › javascript
JavaScript round a number to 2 decimal places (with examples)
December 11, 2022 - Then round the number to x decimal places. Hence, the data type of result will be a string. You can verify by using the typeof function. var a = 5.678948; let b = 10.257683; let result1 = a.Tofixed(); let result2 = b.toFixed(2); console.log(result1) console.log(result2) console.log(typeof result2)Code language: JavaScript (javascript)
🌐
W3docs
w3docs.com › javascript
How to Format a Number with Two Decimals in JavaScript
Javascript toLocaleString method ... console.log(format(2.345)); // "2.35" Run > Reset · One of the methods used is the toFixed method which returns a string: Javascript toFixed method ·...
🌐
Go Make Things
gomakethings.com › converting-numbers-to-strings-with-vanilla-javascript
Converting numbers to strings with vanilla JavaScript | Go Make Things
You can combine parseFloat() with Number.toFixed() to add decimals. // returns 42.00 let answer = parseFloat('42').toFixed(2); Here’s a demo. Convert a number to a string.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
And if we place one more dot, then JavaScript knows that the decimal part is empty and now uses the method. Also could write (123456).toString(36). One of the most used operations when working with numbers is rounding. There are several built-in functions for rounding: ... Rounds down: 3.1 becomes 3, and -1.1 becomes -2.