numbro icon indicating copy to clipboard operation
numbro copied to clipboard

en-IN localization and customizable grouping

Open gwynjudd opened this issue 7 years ago • 16 comments

Helps to address the grouping issues in #2 and #235

Added support for customizable grouping widths. In the delimiters, specify group: [2,3], then format() will group like this

12,00,00,000

To make this work, we build up the grouping regex according to the group configuration. For en-IN, we get this:

/(\d)(?=(?:\d{2})*(?:\d{3})(?!\d))/

It matches a single digit, followed by non capturing look-ahead that matches zero or more 2 digit groups, followed by a 3 digit group.

The default for the group property is [3] which matches the current behaviour of grouping by thousands.

It should be possible to pass [4] and get grouping by ten thousands for e.g. Japanese. I'm not aware of more complex groupings.

gwynjudd avatar Mar 29 '17 04:03 gwynjudd

I should point out that I don't have confidence in the abbreviations, ordinal, currencyFormat and the other formats (e.g. fourDigits). I didn't really know what they should be, but I wanted to do the customizable grouping part - someone with experience in number formatting in India might have suggestions.

gwynjudd avatar Mar 29 '17 04:03 gwynjudd

letting this one open a bit more to see if someone has an opinion. Ok with you?

BenjaminVanRyseghem avatar Mar 30 '17 11:03 BenjaminVanRyseghem

@BenjaminVanRyseghem yes, if you could add the help wanted tag that would probably by a good idea.

gwynjudd avatar Mar 30 '17 19:03 gwynjudd

I'm just learning about this project, and was glad to see that it has gotten a lot further than it was in numeral.js. One big thing I was looking for is whether this issue (along with the Japanese issues mentioned in the links above) are being addressed.

This appears to still be open. I do work with a couple of people who would be able to answer questions about number formats in Tamil and Japanese. So, if there are questions that would cause the changes for those languages to be incorporated, I'll be glad to get them answered.

DDoyle022 avatar Mar 05 '18 23:03 DDoyle022

There is now the option delimiters.thousandsSize that is language specific. It should cover those cases :smile:

If someone is willing to test and report :smile:

BenjaminVanRyseghem avatar Mar 06 '18 08:03 BenjaminVanRyseghem

Are the localization files going to be added/updated? Because if not, it will take me a fair amount of time to become familiar enough with the code to do that.

DDoyle022 avatar Mar 06 '18 21:03 DDoyle022

to do that.

To do what?

BenjaminVanRyseghem avatar Mar 06 '18 22:03 BenjaminVanRyseghem

Be the someone who is willing to test and report.

DDoyle022 avatar Mar 07 '18 20:03 DDoyle022

numbro.language(); //> "en-US"
numbro.languageData().delimiters.thousandsSize = 2;
numbro(100000).format(","); //> 10,00,00

BenjaminVanRyseghem avatar Mar 07 '18 21:03 BenjaminVanRyseghem

@BenjaminVanRyseghem, solution above does not solve the case completelly. In Indian system

  • 100000 (one hundred thousand) would be 1,00,000;
  • 10000000 (ten million) would be 1,00,00,000.

Do you see the pattern? The very first thousand is delimited by 3 chars, then delimiter comes every 2 chars, following from right to the left.

pavelmickevic avatar Mar 08 '18 17:03 pavelmickevic

Apparently, thousandsSize is not that kind of a property in setup; rather it should be something like delimiterGroups property, but I cannot figure out a design for that, at the moment.

Maybe:

delimiterGroups: [2, 3] // default [2]

pavelmickevic avatar Mar 08 '18 17:03 pavelmickevic

I see! I will see if I can add a function like this:

thousandsSize = 2; //> 10,00,00
thousandsSize = (input) => {
    let length = input.length;
    if (length <= 5) {
        return 2;
    }

    let rest = length - 2;
    let result = [];
    for (let i = 0; i < Math.floor(rest/3), i++) {
        result.push(3);
    }
    
    result.push(2);
    return result;
} //> 100,000,00

BenjaminVanRyseghem avatar Mar 09 '18 09:03 BenjaminVanRyseghem

The number you have in the final comment is backwards. It is every 2 places, except for the very last one which is 3 places. You have it the other way around. 100 1,000 10,000 1,00,000 10,00,000 1,00,00,000

DDoyle022 avatar Mar 12 '18 21:03 DDoyle022

When will the en-IN be merged. We are in need of this urgently.

ghost avatar Oct 08 '18 07:10 ghost

@BenjaminVanRyseghem is there any intention of ever merging this code?

pdrlima avatar Jun 15 '21 05:06 pdrlima

this PR is quite out-dated, has conflicts, and I have no idea about how en-IN should work.

So if someone with indian's cardinal knowledge is willing to take care of this, I will definitely push for it. But in the current situation, there is sadly not much I can do

BenjaminVanRyseghem avatar Jun 15 '21 06:06 BenjaminVanRyseghem