to-words icon indicating copy to clipboard operation
to-words copied to clipboard

name in currencyOptions not working

Open anil-suthar opened this issue 3 years ago • 4 comments

I tried below code, it works well but name config is not working. It always considers plural

{
    "localeCode": "en-IN",
    "converterOptions": {
        "currency": true,
        "currencyOptions": {
            "name": "Rupee",
            "plural": "Rupees",
            "symbol": "",
            "fractionalUnit": {
                "name": "Paisa",
                "plural": "Paise",
                "symbol": ""
            }
        }
    }
}

Test#1: 1.01 outputs One Rupees And One Paise Only but should be One Rupee And One Paisa Only Test#2: 1.00 outputs One Rupees Only but should be One Rupee Only

Can you please check this or am I missing anything ?

anil-suthar avatar Mar 13 '23 14:03 anil-suthar

Any chance to check this issue ? @mastermunj

anil-suthar avatar Apr 24 '23 11:04 anil-suthar

@anil-suthar This seems like a breaking change. Will you be able to raise a PR for the same?

mastermunj avatar Apr 26 '23 06:04 mastermunj

@mastermunj I checked the code here : https://github.com/mastermunj/to-words/blob/main/dist/ToWords.js and I think you should replace the following code blocks :

Replace : (line# 161)

if (currencyOptions.plural) {
    words.push(currencyOptions.plural);
}

with

if (Number(split[0]) > 1 && currencyOptions.plural) {
    words.push(currencyOptions.plural);
} else {
    words.push(currencyOptions.name);
}

and Replace : (line# 180)

wordsWithDecimal.push(currencyOptions.fractionalUnit.plural);

with

if (Number(split[1]) > 1 && currencyOptions.fractionalUnit.plural) {
    wordsWithDecimal.push(currencyOptions.fractionalUnit.plural);
} else {
    wordsWithDecimal.push(currencyOptions.fractionalUnit.name);
}

anil-suthar avatar May 01 '23 13:05 anil-suthar

Hi @anil-suthar have a look at this https://github.com/mastermunj/to-words/pull/1470

hardiksondagar avatar Dec 15 '23 13:12 hardiksondagar