Convert the number into a string, match the number up to the second decimal place:

function calc(theform) {
    var num = theform.original.value, rounded = theform.rounded
    var with2Decimals = num.toString().match(/^-?\d+(?:\.\d{0,2})?/)[0]
    rounded.value = with2Decimals
}
<form onsubmit="return calc(this)">
Original number: <input name="original" type="text" onkeyup="calc(form)" onchange="calc(form)" />
<br />"Rounded" number: <input name="rounded" type="text" placeholder="readonly" readonly>
</form>

The toFixed method fails in some cases unlike toString, so be very careful with it.

Answer from Gumbo on Stack Overflow
🌐
ThisCodeWorks
thiscodeworks.com › javascript-truncate-number-to-two-decimal-places-without-rounding-stack-overflow › 619e399485dcaf00159171e9
javascript - Truncate number to two decimal places without rounding - Stack Overflow | thiscodeWorks
num = num.toString(); //If it's not already a String num = num.slice(0, (num.indexOf("."))+3); //With 3 exposing the hundredths place Number(num); //If you need it back as a Number content_copyCOPY https://stackoverflow.com/questions/4187146/truncate-number-to-two-decimal-places-without-rounding
Discussions

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
rounding - Formatting a number with exactly two decimals in JavaScript - Stack Overflow
I have this line of code which rounds my numbers to two decimal places. But I get numbers like this: 10.8, 2.4, etc. These are not my idea of two decimal places so how I can improve the following? ... More on stackoverflow.com
🌐 stackoverflow.com
Delete digits after two decimal points, without rounding the value in javascript/jquery
Find answers to Delete digits after two decimal points, without rounding the value in javascript/jquery from the expert community at Experts Exchange More on experts-exchange.com
🌐 experts-exchange.com
May 28, 2018
dom events - Obtain two decimal places in JavaScript without rounding to the next bigger number - Stack Overflow
What I want to achieve is to actually ... 5.00 as rounding to two decimals. ... Please check the article already discussed. Click here ... Or convert the number into a string, match the number up to the second decimal place and turn it back into a number: Number(15.7784514000.toString().match(/^\d+(?:\.\d{0,2})?... More on stackoverflow.com
🌐 stackoverflow.com
July 25, 2016
🌐
Adobe Acrobat
acrobatusers.com › forum › javascript › rounding-2-decimal-places-without-rounding
Rounding to 2 decimal places without rounding up
February 23, 2011 - Have you looked at the "parseInt" object or the 'Math.floor' method // document level script using parseInt to truncate to nDec places function Int(nValue, nDec) { // parseInt nValue to nDec places var nAdj = Math.pow(10, parseInt(nDec)) return parseInt(nValue * nAdj) / nAdj; } // document level script using Math.floor to truncate to nDec places function Floor(nValue, nDec) { // truncate a value at nDec places var nAdj = Math.pow(10, Math.floor(nDec)) return Math.floor(nValue * nAdj) / nAdj; } // custom calculation script to truncate computation to nDec places var m1 = this.getField("miles1");
🌐
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
This method ensures no rounding, preserving exact precision. 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
🌐
QuickRef.ME
quickref.me › home › how to truncate a number to a given number of decimal places without rounding in javascript - quickref.me
How to truncate a number to a given number of decimal places without rounding in JavaScript - QuickRef.ME
This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function. Let's define this short function: const toFixed = (n, fixed) => `${n}`.match(new RegExp(`^-?\\d+(?:\.\\d{0,${fixed}})?`))[0]; const ...
Top answer
1 of 16
1155

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

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

const 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:

const 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:

function 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:

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

This genericity also provides some cool stuff:

round(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:

round(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:

function 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:

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

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

Show code snippet

function 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);
table {
  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;
}
<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
🌐
Experts Exchange
experts-exchange.com › questions › 29101720 › Delete-digits-after-two-decimal-points-without-rounding-the-value-in-javascript-jquery.html
Solved: Delete digits after two decimal points, without rounding the value in javascript/jquery | Experts Exchange
May 28, 2018 - Delete digits after two decimal points, without rounding the value in javascript/jquery var a=987.687 but i need the value like 987.68 how to get value like that · Misha · Try this code: var a = 987.687; var b = a.toString().substring(0, a.toString().indexOf(".") + 3) Select allOpen in new window · leakim971 · a = a.toFixed(2); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › toFixed
Number.prototype.toFixed() - JavaScript - MDN Web Docs
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...
🌐
OutSystems
outsystems.com › forums › discussion › 90504 › decimal-with-2-digits-without-round-off
Decimal with 2 digits without round off | OutSystems
August 11, 2023 - I need decimal value with 2 decimal places for the amount and it should not be rounded instead it should be cut off to 2 decimal places · Example: 4816.875 should display as 4816.87 or 3699.095 should display as 3699.09
Top answer
1 of 16
5572

Use Math.round() :

Math.round(num * 100) / 100

Or to be more specific and to ensure things like 1.005 round correctly, use Number.EPSILON :

Math.round((num + Number.EPSILON) * 100) / 100
2 of 16
4382

If the value is a text type:

parseFloat("123.456").toFixed(2);

If the value is a number:

var numb = 123.23454;
numb = numb.toFixed(2);

There is a downside that values like 1.5 will give "1.50" as the output. A fix suggested by @minitech:

var numb = 1.5;
numb = +numb.toFixed(2);
// Note the plus sign that drops any "extra" zeroes at the end.
// It changes the result (which is a string) into a number again (think "0 + foo"),
// which means that it uses only as many digits as necessary.

It seems like Math.round is a better solution. But it is not! In some cases it will not round correctly:

Math.round(1.005 * 100)/100 // Returns 1 instead of expected 1.01!

toFixed() will also not round correctly in some cases (tested in Chrome v.55.0.2883.87)!

Examples:

parseFloat("1.555").toFixed(2); // Returns 1.55 instead of 1.56.
parseFloat("1.5550").toFixed(2); // Returns 1.55 instead of 1.56.
// However, it will return correct result if you round 1.5551.
parseFloat("1.5551").toFixed(2); // Returns 1.56 as expected.

1.3555.toFixed(3) // Returns 1.355 instead of expected 1.356.
// However, it will return correct result if you round 1.35551.
1.35551.toFixed(2); // Returns 1.36 as expected.

I guess, this is because 1.555 is actually something like float 1.55499994 behind the scenes.

Solution 1 is to use a script with required rounding algorithm, for example:

function roundNumber(num, scale) {
  if(!("" + num).includes("e")) {
    return +(Math.round(num + "e+" + scale)  + "e-" + scale);
  } else {
    var arr = ("" + num).split("e");
    var sig = ""
    if(+arr[1] + scale > 0) {
      sig = "+";
    }
    return +(Math.round(+arr[0] + "e" + sig + (+arr[1] + scale)) + "e-" + scale);
  }
}

It is also at Plunker.

Note: This is not a universal solution for everyone. There are several different rounding algorithms. Your implementation can be different, and it depends on your requirements. See also Rounding.

Solution 2 is to avoid front end calculations and pull rounded values from the backend server.

Another possible solution, which is not a bulletproof either.

Math.round((num + Number.EPSILON) * 100) / 100

In some cases, when you round a number like 1.3549999999999998, it will return an incorrect result. It should be 1.35, but the result is 1.36.

🌐
CodeParrot
codeparrot.ai › blogs › javascript-round-to-2-decimal-places-a-complete-guide
Eight AI Trends Reshaping Technology in 2025 | .News
Disclaimer: References to any specific company, product or services on this Site are not controlled by GoDaddy.com LLC and do not constitute or imply its association with or endorsement of third party advertisers
🌐
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 - But why exactly two decimal places? Mainly, it aligns with the most common monetary format used globally, thus simplifying financial calculations. Moreover, in many statistical reports, a two-decimal precision strikes the right balance between accuracy and comprehensibility. Rounding numbers in JavaScript might seem straightforward at first glance, but it encompasses several methods, each with its unique applications.
🌐
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 - JavaScript provides several methods to round numbers, but rounding to a specific number of decimal places requires additional steps. Rounding to 2 decimal places involves converting the number to a string representation, manipulating the string, and converting it back to a number.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › round-off-a-number-upto-2-decimal-place-using-javascript
Round off a number upto 2 decimal place using JavaScript - GeeksforGeeks
January 20, 2020 - rounded_number = Math.round(number ... <script type="text/javascript"> function roundOff() { pi = 3.14159265359; twoPlaces = Math.round(pi * 100) / 100; document.querySelector('.output').textContent = twoPlaces; } </script> </body> ...
🌐
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. ... Requires a bit more code and understanding of mathematical operations. One of the challenges in JavaScript is the precise representation of floating-point numbers.
🌐
Attacomsian
attacomsian.com › blog › javascript-round-numbers
Round a number to 2 decimal places in JavaScript
November 27, 2022 - Alternatively, you can use the toFixed() method to round a number to 2 decimal places in JavaScript.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Numbers
December 18, 2024 - Removes anything after the decimal point without rounding: 3.1 becomes 3, -1.1 becomes -1. Here’s the table to summarize the differences between them: These functions cover all of the possible ways to deal with the decimal part of a number. But what if we’d like to round the number to n-th digit after the decimal? For instance, we have 1.2345 and want to round it to 2 digits, getting only 1.23.