If you're doing this to several fields, or doing it quite often, then perhaps a plugin is the answer.
Here's the beginnings of a jQuery plugin that formats the value of a field to two decimal places.
It is triggered by the onchange event of the field. You may want something different.

<script type="text/javascript">

    // mini jQuery plugin that formats to two decimal places
    (function($) {
        $.fn.currencyFormat = function() {
            this.each( function( i ) {
                $(this).change( function( e ){
                    if( isNaN( parseFloat( this.value ) ) ) return;
                    this.value = parseFloat(this.value).toFixed(2);
                });
            });
            return this; //for chaining
        }
    })( jQuery );

    // apply the currencyFormat behaviour to elements with 'currency' as their class
    $( function() {
        $('.currency').currencyFormat();
    });

</script>   
<input type="text" name="one" class="currency"><br>
<input type="text" name="two" class="currency">
Answer from meouw on Stack Overflow
🌐
ASPSnippets
aspsnippets.com › questions › 138804 › Format-string-number-with-commas-and-two-decimals-in-jQuery › answers
Format string number with commas and two decimals in jQuery
August 27, 2024 - <input id="txtNumber" type="text" value="1200900,56" /> <input id="btnSubmit" type="button" value="Submit" /> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#btnSubmit").click(function () { var parts = $("#txtNumber").val().split(','); parts[0] = parseFloat(parts[0].replace(/\D/g, "")).toLocaleString('de-DE'); $("#txtNumber").val(parts[0] + (parts[1] ?
🌐
GitHub
github.com › customd › jquery-number
GitHub - customd/jquery-number: Easily format numbers for display use. Replace numbers inline in a document, or return a formatted number for other uses.
Number: The number you want to format. $.number( 5020.2364 ); // Outputs 5,020 · Decimal Places: The number of decimal places you wish to see. Defaults to 0. $.number( 5020.2364, 2 ); // Outputs: 5,020.24 ·
Starred by 443 users
Forked by 388 users
Languages   JavaScript
🌐
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...
Find elsewhere
🌐
Devcurry
devcurry.com › 2010 › 06 › round-off-decimal-to-2-places-in-jquery.html
Round off Decimal to 2 places in jQuery
<html xmlns="http://www.w3.org... <input id="txtNum" type="text" /> </body> </html> Here we use the toFixed() which Formats a number using fixed-point notation....
🌐
DotNetCurry
dotnetcurry.com › jquery › 1076 › using-jquery-add-commmas-numbers-textbox
Automatically add Commas to a Number in a TextBox | DotNetCurry
The script uses a regular expression to add commas. Passing a number like 23456789.12345 produces 23,456,789.12345, which is the desired result. Live Demo: http://www.jquerycookbook.com/demos/S2-InputControls/12-NumberFormatting.html · The script we saw works fine, but what if at a later date, ...
🌐
DevExtreme
js.devexpress.com › jQuery › Documentation › Guide › Common › Value_Formatting
DevExtreme jQuery/JS - Value Formatting | jQuery/JS Documentation
const number = 1234.567; // Leave the first digit before the decimal point and round up the decimal format: "0.0" // 4.6 const smallNumber = 0.1234; // Display nothing in place of a digit format: "#.#" // .1 const largeNumber = 123456.789; // Add a group separator format: ",##0.###" // 123,456.789
🌐
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 below example, we format 9.1291754 to a number with two decimals. We use of Math.floor() method for formatting the number. <html> <body> <h3>JavaScript Math.floor() Method</h3> <p>Format a nubmer with 2 decimals:</p> <p id="input"></p> <p id="result"></p> <script> var num = 9.1291754; ...
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript format number with commas and decimal places | example
JavaScript format number with commas and decimal places | Code
December 13, 2022 - // With custom settings, forcing a "US" locale to guarantee commas in output let number2 = 1234.56789; // floating point example number2.toLocaleString('en-US', {maximumFractionDigits:2}) // "1,234.57"
🌐
W3Schools
w3schools.com › howto › howto_js_format_number_dec.asp
How To Format a Number with Two Decimals
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.
🌐
IQCode
iqcode.com › code › javascript › jquery-number-format-comma
jquery number format comma Code Example
var number = 1557564534; document.body.innerHTML = number.toLocaleString(); // 1,557,564,534
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › NumberFormat
Intl.NumberFormat - JavaScript | MDN
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.