
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
jquery-number
Advanced tools
This is a jQuery plugin which allows developers to easily format numbers for display use. Allows users to replace numbers inline in a document, or return a formatted number for other uses.
This is a jQuery plugin which allows developers to easily format numbers for display use. Allows users to replace numbers inline in a document, or return a formatted number for other uses.
Requires jQuery 1.6 or greater.
See our jQuery Number Format article for more information.
The number method takes up to four parameters, but only the first one is required.
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
Decimal Separator: The character(s) to use as a decimal separator. Defaults to '.'.
$.number( 135.8729, 3, ',' ); // Outputs: 135,873
Thousands Separator: The character(s) to use as a thousands separator. Defaults to ','.
$.number( 5020.2364, 1, ',', ' ' ); // Outputs: 5 020,2
When targeting a collection of input elements, you can have the number format plugin automatically format the users input based on your format settings.
$('input.number').number( true, 2 );
Passing true
to the number parameter, indicates that you want the value of the field or element to be effected, instead
of placing the passed number into the field or element. All other parameters are as decribed above.
When the user types, their input will automatically be converted in the correct format. This also attaches .val() hooks
which allow you to continue using .val()
to set your input elements, and you don't need to worry about handling the formatting.
Automatic paste formatting is also supported.
$('.selector').number( 1234, 2 ); // Changes the text value of the element matching selector to the formatted number.
Assuming we have the following structure:
<p>
<span class="number">1025.8702</span>
<span class="number">18023</span>
<span class="number">982.3</span>
<span class="number">.346323</span>
</p>
We can use this JavaScript:
// the 'true' signals we should read and replace the text contents of the target element.
$('span.number').number( true, 2 )
And come away with this result:
<p>
<span class="number">1,025.87</span>
<span class="number">18,023.00</span>
<span class="number">982.30</span>
<span class="number">0.35</span>
</p>
FAQs
This is a jQuery plugin which allows developers to easily format numbers for display use. Allows users to replace numbers inline in a document, or return a formatted number for other uses.
The npm package jquery-number receives a total of 3,921 weekly downloads. As such, jquery-number popularity was classified as popular.
We found that jquery-number demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.