Categories
JavaScript Answers

How to add thousand separator with HTML number input with JavaScript?

Spread the love

Sometimes, we want to add thousand separator with HTML number input with JavaScript.

In this article, we’ll look at how to add thousand separator with HTML number input with JavaScript.

How to add thousand separator with HTML number input with JavaScript?

To add thousand separator with HTML number input with JavaScript, we use the autoNumeric library.

To install it, we add

<script src="https://unpkg.com/autonumeric"></script>

Then we write

<input type="text" value="1234.56" />

to add an input.

Then we write

const domElement = document.querySelector("input");
const anElement = new AutoNumeric(domElement);

to select the input with querySelector.

And we convert it to an input with the thousand separator in its value by calling the AutoNumeric constructor with domElement.

Conclusion

To add thousand separator with HTML number input with JavaScript, we use the autoNumeric library.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *