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

How do I round a JavaScript number to 2 decimal places?
36.99300003051758 I'm receiving this kind of value how can round of this More on discourse.nodered.org
๐ŸŒ discourse.nodered.org
1
0
July 1, 2022
How do I make only 2 decimal places?
Anything with javascript it is worth googling something like "javascript 2 decimal places." You will get your answer pretty quick. I am a pretty experienced JS dev and I google stuff like this all the time ยท Thank you so much! I actually did, for about 45 minutes but I didn't know the syntax. More on community.retool.com
๐ŸŒ community.retool.com
1
0
July 26, 2021
how to round to 2 decimal places with typescript?
It's not a typescript question, it's a javascript question (maybe even just a math question). But what you are looking for is the toFixed() method. (5).toFixed(2) // returns the string "5.00" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed btw : your first example "123.45 => should return 123.46" there should be no rounding here it should return "123.45", and toFixed() will take care of rounding for you. More on reddit.com
๐ŸŒ r/typescript
9
1
December 25, 2019
JavaScript Rounding Numbers to a Maximum of Two Decimal Places
To mitigate this, a common approach ... decimal arithmetic. This library can handle very large and very small numbers with a high degree of accuracy, making it ideal for applications that require precise calculations. Integrating such a library can help avoid the pitfalls of native JavaScript arithmetic and ensure that your rounding operations are reliable and accurate. How do I round a number to 2 decimal places ... More on reddit.com
๐ŸŒ r/MailDevNetwork
1
August 8, 2023
๐ŸŒ
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 - Use code 2026SKY25 at checkout. ... ลukasz Holeczek Follow ลukasz Holeczek on GitHub Connect with ลukasz Holeczek on LinkedIn Follow ลukasz Holeczek on X (Twitter) ... In the ever-evolving landscape of web development, mastering JavaScript nuances can significantly enhance your applicationsโ€™ functionality and user experience. A joint yet critical operation in numerous computing scenarios is to round numbers to a specific number of decimal places.
๐ŸŒ
CodeParrot
codeparrot.ai โ€บ blogs โ€บ javascript-round-to-2-decimal-places-a-complete-guide
JavaScript Round to 2 Decimal Places: A Complete Guide
JavaScript's floating-point arithmetic can cause unexpected results, especially in JavaScript Round to 2 Decimal Places. Adding Number.EPSILONโ€”the smallest possible value that can be added to 1 to yield a result greater than 1โ€”helps mitigate these errors.
๐ŸŒ
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 - Debug and fix code errors with Zipy Error Monitoring. ... 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 ...
๐ŸŒ
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....
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Favtutor
favtutor.com โ€บ articles โ€บ round-to-two-decimal-places-javascript
Round to 2 Decimal Places in JavaScript (with code)
December 14, 2023 - It rounds the number to the nearest integer and returns the output. ... If we want to round the number to 2 decimal places, we need to multiply the number by 100 and then pass it to the function, and finally divide the rounded value by 100.
๐ŸŒ
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 - You can round a number to 2 decimal places in JavaScript using methods like toFixed(), Math.round(), toPrecision(), custom helper functions, or external libraries like lodash. Use the toFixed() method for rounding numbers to a specific number ...
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_tofixed.asp
JavaScript toFixed() Method
The toFixed() method rounds the string to a specified number of decimals.
๐ŸŒ
Roblog
robiul.dev โ€บ round-to-2-decimal-places-in-javascript
How to Round a Number to 2 Decimal Places in JavaScript
May 28, 2023 - Finally, we multiply the truncated number by 0.01 This multiplication restores the original decimal places, effectively rounding the number to 2 decimal places. Note: it's important to note that this method relies on integer manipulation and may not be suitable for all rounding scenarios. Consider the specific requirements of your use case, such as handling negative numbers or ensuring consistent behavior with rounding rules, when selecting this approach. So far, we have discussed 5 ways of rounding but all of these were using javascript built in methods.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-format-a-number-with-two-decimals-in-JavaScript
How to format a number with two decimals in JavaScript?
October 31, 2023 - In the above program, we have used the Math.round() method which rounds a number to a number with two decimal positions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-parse-float-with-two-decimal-places-in-javascript
How to Parse Float with Two Decimal Places in JavaScript? | GeeksforGeeks
Below are the approaches to parse ... the string isn't numeric, it returns NaN. To limit the number to two decimal places, use toFixed(2), which rounds the result....
Published ย  January 9, 2025
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ round-off-a-number-upto-2-decimal-place-using-javascript
Round off a number upto 2 decimal place using JavaScript | GeeksforGeeks
August 7, 2024 - For example, a value of 15.6 would be split into two numbers, i.e. 15 and 0.6 Here are a few methods discussed. These are the following methods: Table of Content Javascript String split() Method
๐ŸŒ
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
Then round the number to the nearest integer using Math.round() and divide the answer by 10 to the power of 2: ... You may occasionally get rounding errors using this method. For example, if you round 1.005 to two decimal places, you would expect ...
๐ŸŒ
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; ...