skip to Main Content

The Intl.NumberFormat for currency PGK, it is showing PGK as narrow symbol instead of K
What can I do to fix this?

I cannot replace the Intl.NumberFormat function and I cannot add additional code after the function is called, I can only change the the arguments.

const number = 123456.789;

console.log(new Intl.NumberFormat('en', { style: 'currency', currency: 'PGK', currencyDisplay: "narrowSymbol", }).format(number));
// Expected output: "K 123.456,79"
// Output: "PGK 123.456,79"

console.log(new Intl.NumberFormat('en', { style: 'currency', currency: 'MMK', currencyDisplay: "narrowSymbol", }).format(number));
// Output: "K 123.456,79"

2

Answers


  1. Chosen as BEST ANSWER

    I ended up overring the function to fix the currencies with a problem.

    if (!new Intl.NumberFormat().custom) {
        var NumberFormatOriginal = Intl.NumberFormat;
        Intl.NumberFormat = function (locale, options) {
            return {
                custom: true,
                format: function (number) {
                    options.currencySign = "accounting";
                    var output = new NumberFormatOriginal(locale, options).format(number);
                    if (options?.style === "currency" && options?.currencyDisplay === "narrowSymbol" && options.currency) {
                        switch (options.currency) {
                            case "PGK":
                                output = output.replace(options.currency, "K");
                                break;
                            default:
                                break;
                        }
                    }
                    return output;
                }
            };
        }
    }


  2. It doesn’t fully support all world currencies yet, and when it’s not supported it just returns the currency code, for example: (ZQY currency doesn’t even exist):

    console.log(new Intl.NumberFormat('en', { style: 'currency', currency: 'ZQY' }).format(123131321));
    

    Some other currencies currently not supported:

    ["CRC","CUC","CUP","CVE","CZK","DJF","LSL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRO","MUR","MVR","MWK","MYR","MZN","NAD","NGN","NIO","NOK","NPR","OMR","PAB","PEN","PGK","PKR","PLN","TZS","UAH","UGX","UYU","UZS","VEF","VUV","WST","XDR","YER","ZAR","ZMW","ZWD"]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search