Reputation: 1703
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?
Upvotes: 3
Views: 513
Reputation: 1703
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.. =)
Upvotes: 1