Wednesday 25 June 2014

Number Formatting Using JavaScript

Tested Approach:
number.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');Short solution #2:

Alternate Solution:
number.toFixed(2).replace(/./g, function(c, i, a) {
return i && c !== "." && !((a.length - i) % 3) ? ',' + c : c;
});

Example:
5543.45 will be converted to 5,543.45.

No comments:

Post a Comment

Run Postman API remote or code or command line

POSTMAN is used to run the APIs generally. What if we want to create a collection in postman and run it from some other code or command l...