Whereas usually a large currency value like USD 123456789 is formatted as USD 123,456,789, here in Pakistan, such a number is formatted as Rs. 12,34,56,789/- (last 3 digits grouped, then every 2 digits grouped together, the entire string followed by a /-.
Is it possible to use the default Angular Currency pipe to achieve this? If not, what's the correct regex that I can use to achieve this formatting in my custom pipe's transform method?
Searching more around SO, I found this post which addresses the same problem:
Displaying a number in Indian format using Javascript
The relevant code snippet is this:
let amount = value.toString();
var lastThree = amount.substring(amount.length - 3);
var otherNumbers = amount.substring(0, amount.length - 3);
if(otherNumbers != '') lastThree = ',' + lastThree;
var result = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
This works fine for my case as well.. =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With