(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
🌐
Mikemcl
mikemcl.github.io › decimal.js
decimal.js API
The value of a Decimal is stored in a normalised base 10000000 floating point format.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript | MDN
js · (1000000000000000128).toString(); // '1000000000000000100' (1000000000000000128).toFixed(0); // '1000000000000000128' However, choosing a digits precision that's too high can return unexpected results, because decimal fractional numbers cannot be represented precisely in floating point.
🌐
npm
npmjs.com › package › decimal-format
decimal-format - npm
import DecimalFormat from 'decimal-format'; const df = new DecimalFormat('#,##0.0#'); df.format(1234.995); // 1,235.0 df.format(1234.956); // 1,234.96 const df1 = new DecimalFormat('#,##0.0#%'); df1.format(0.34995); // 35.0% const df2 = new DecimalFormat('#,##0.0#‰'); df2.format(0.034993); // 34.99‰ const df3 = new DecimalFormat('¥#,##0.00元'); df3.format(1234.995); // ¥1,235.00元 const df4 = new DecimalFormat('0.00E'); df4.format(1234); // 1.23E3 const df5 = new DecimalFormat('0.00E+'); df5.format(1234); // 1.23E+3
      » npm install decimal-format
    
Published   Aug 28, 2025
Version   4.1.1
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat
Intl.NumberFormat - JavaScript | MDN
In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument: js · const number = 123456.789; // German uses comma as decimal separator and period for thousands console.log(new Intl.NumberFormat("de-DE").format(number)); // 123.456,789 // Arabic in most Arabic speaking countries uses real Arabic digits console.log(new Intl.NumberFormat("ar-EG").format(number)); // ١٢٣٤٥٦٫٧٨٩ // India uses thousands/lakh/crore separators console.log(new Intl.NumberFormat("en-IN").format(number)); // 1,23,456.789 // the nu extension key requests a numbering system, e.g.
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › number › number formatting
Formatting numeric values in JavaScript - 30 seconds of code
February 14, 2024 - Rounding a number to a specific number of decimal places is pretty common. We can use Math.round() and template literals to round the number to the specified number of digits.
🌐
W3Schools
w3schools.com › jsref › jsref_tofixed.asp
W3Schools.com
cssText getPropertyPriority() ... · The toFixed() method converts a number to a string. The toFixed() method rounds the string to a specified number of decimals....
Find elsewhere
🌐
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 - To round a number to two decimal places we can manipulate the number before and after using Math.round(). By multiplying the number by 100, rounding it, and then dividing by 100, we effectively round the number to two decimal places.
🌐
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"
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-math-exercise-5.php
JavaScript Math: Format a number up to specified decimal places - w3resource
The code defines a function called "decimals()" which takes two parameters: 'n' (a number) and 'd' (the number of decimal places to format).
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-format-number-to-two-decimal-places
Format a number to 2 Decimal places in JavaScript | bobbyhadz
Use the toFixed() method to format a number to 2 decimal places, e.g. num.toFixed(2). The toFixed method takes a parameter, representing how many digits should appear after the decimal and returns the result. index.js ·
🌐
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.
🌐
GitHub
github.com › MikeMcl › decimal.js
GitHub - MikeMcl/decimal.js: An arbitrary-precision Decimal type for JavaScript · GitHub
The value of a Decimal is stored in a floating point format in terms of its digits, exponent and sign, but these properties should be considered read-only. x = new Decimal(-12345.67); x.d // [ 12345, 6700000 ] digits (base 10000000) x.e // 4 ...
Author   MikeMcl
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat › NumberFormat
Intl.NumberFormat() constructor - JavaScript | MDN
const amount = 3500; console.log(new Intl.NumberFormat().format(amount)); // '3,500' if in US English locale ... const amount = 3500; new Intl.NumberFormat("en-US", { style: "decimal", }).format(amount); // '3,500' new Intl.NumberFormat("en-US", { style: "percent", }).format(amount); // '350,000%'
🌐
npm
npmjs.com › package › decimal.js
decimal.js - npm
The value of a Decimal is stored in a floating point format in terms of its digits, exponent and sign, but these properties should be considered read-only. x = new Decimal(-12345.67); x.d // [ 12345, 6700000 ] digits (base 10000000) x.e // 4 ...
      » npm install decimal.js
    
Published   Jul 06, 2025
Version   10.6.0
Author   Michael Mclaughlin
🌐
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.
🌐
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.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Numbers_and_strings
Numbers and strings - JavaScript | MDN
In JavaScript, numbers are implemented in double-precision 64-bit binary format IEEE 754 (i.e., a number between ±2^−1022 and ±2^+1023, or about ±10^−308 to ±10^+308, with a numeric precision of 53 bits).