How to format number with commas and decimal in Javascript
By FoxLearn 2/16/2024 9:39:09 AM 49
This post shows you how to format number with commas and decimal in Javascript.
For example:
1234.542 and you want to format 1,234.54
You can use regular expression to solve the problem.
var value =1234.542 var parts = value.toFixed(2).split("."); var num = parts[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") + (parts[1] ? "." + parts[1] : "");
If you want result 1,234.542 then change toFixed(2) to toFixed(3)
- How to Add Active Navigation Class Based on URL
- How to Display popup message in Javascript
- How to Show message instead of alert
- How to fix 'Uncaught TypeError: Cannot read property 'fn' of undefined'
- How to Format numbers with commas in Javascript
- How to Pass string parameter in an onclick function
- How to get @Url.Action url in a separate script file?
- How to use sweetalert2
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024
What Are RESTful Web Services?
02/19/2024