(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
Create a Website Make a Website ... Header Example Website · 2 Column Layout 3 Column Layout 4 Column Layout Expanding Grid List Grid View Mixed Column Layout Column Cards Zig Zag Layout Blog Layout · Google Charts Google Fonts Google Font Pairings Google Set up Analytics · Convert Weight Convert Temperature Convert Length Convert Speed · Get a Developer Job Become a Front-End Dev. Hire Developers ... Learn how to format a number with two decimals in JavaScript...
🌐
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. It converts the number to a string and keep a specified number of decimals. ... Example: In below example we are using the toFixed() method to format a number with two decimals.
🌐
Codedamn
codedamn.com › news › javascript
JavaScript round a number to 2 decimal places (with examples)
December 11, 2022 - 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. “e+2”, 2 is for 2 decimal places.
🌐
TutorialsPoint
tutorialspoint.com › how-to-format-a-number-with-two-decimals-in-javascript
How to format a number with two decimals in JavaScript?
In the above syntax toFixed() is the method of formatting a number with twoIn the above syntax toFixed() is the method of formatting a number with two decimals in JavaScript and number is the number to be formatted with two decimals. STEP 1 ? Declare a variable named "num" and assign a number to the variable. STEP 2 ? Compute num.toFixed(2). The result is formatted with two decimals. ... The example below will illustrate numbers before and after formatting in JavaScript.
🌐
W3docs
w3docs.com › javascript
How to Format a Number with Two Decimals in JavaScript
const format = (num, decimals) => num.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2, }); console.log(format(3.005)); // "3.01" console.log(format(2.345)); // "2.35" ... let num1 = 6.8; let num2 = 264.1364; ...
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

Find elsewhere
🌐
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 - Here’s how you can use it: let number = 5.6789; let roundedNumber = number.toFixed(2); console.log(roundedNumber); Output: 5.68 · In this example, the toFixed(2) method is called on the variable number, which holds the value 5.6789.
🌐
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 ...
🌐
CodeParrot
codeparrot.ai › blogs › javascript-round-to-2-decimal-places-a-complete-guide
JavaScript Round to 2 Decimal Places: A Complete Guide
For instance, prices are usually displayed as $10.99 instead of $10.9876. By focusing on rounding to two decimal places in JavaScript, we ensure accuracy, practicality, and user-friendly results.
🌐
LearnersBucket
learnersbucket.com › home › examples › javascript › learn how to round to 2 decimal places in javascript
Learn how to round to 2 decimal places in javascript - LearnersBucket
September 19, 2019 - To round off any number to any decimal place we can use this method by first multiplying the input number with 10 ^ decimal place, so in our case it is 2 that is Math.round(3.14159265359 * (10 ^ 2)) and then divide it by 10 ^ decimal place like Math.round(3.14159265359 * (10 ^ 2)) / (10 ^ 2) so it ...
🌐
GeeksforGeeks
geeksforgeeks.org › 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   January 9, 2025
🌐
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...
🌐
Favtutor
favtutor.com › articles › round-to-two-decimal-places-javascript
Round to 2 Decimal Places in JavaScript (with code)
December 14, 2023 - In this example, we first multiplied the number by 100 to shift the decimal places two positions to the right. We then use the Math.round() function to round the resulting value to the nearest integer.
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript format number 2 decimals | example code
JavaScript format number 2 decimals | Example code
June 16, 2022 - Use toFixed() method to format number 2 decimals in JavaScript. You have to add the parameter of the toFixed() method to 2, to get the number with two decimals. number.toFixed(x) This method formats a number with a specific number of digits ...
🌐
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 2 decimal places in JavaScript is a common requirement that can be achieved using various methods such as toFixed(), Math.round(), toPrecision(), custom helper functions, and external libraries like lodash.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
For instance, we have 1.2345 and want to round it to 2 digits, getting only 1.23. ... For example, to round the number to the 2nd digit after the decimal, we can multiply the number by 100, call the rounding function ...
🌐
Roblog
robiul.dev › round-to-2-decimal-places-in-javascript
How to Round a Number to 2 Decimal Places in JavaScript
May 28, 2023 - By rounding the average temperature to 2 decimal places, the displayed value becomes 25.94°C. In this scenario rounding the number helps to simplify the temperature representation, making it easier to read and understand without sacrificing ...
🌐
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.