I’m not an expert on regex and I need some help on formatting numbers.
This is what I have:
TheNumber = TheNumber.toString().split(/(?=(?:\d{3})+(?:\.|$))/g).join(",");
Basically, I want TheNumber to be formatted with commas to separate thousands and up to 3 decimal precision with a dot to indicate decimal if there are decimals. It should also work with negative numbers.
I’m not far only that for the moment
3234234.223512 becomes 3,234,234.223,512
Thanks for your help.
I found this Javascript library accounting.js
As mentioned in description.
Accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). It’s lightweight, fully localisable and has zero dependencies.
It does the same as your requirements and even a little more.