Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does N'ko use 3 decimal places for displaying Fixed-Point ("F") numbers while literally every other culture uses 2?

Different cultures use different decimal separators: a dot (1.23) or comma (1,23) or—in the case of Persian (Iran)—a momayyez or slash may be found (۱٫۲۳ or 1/23). I've been testing my library which involves a lot of number parsing (a TimeSpanParser), so have been testing .NET's handling of various numeric formats.

When outputting with the "F" decimal format or Numeric ("N") format, all cultures display 2 decimal places except N'Ko ("nqo" or "nqo-GN"). Why is this so?

Code examples below illustrate this, but it is probably not necessary to understand or follow the code below to answer this question.


Briefly:

Console.WriteLine((1.23456).ToString("F", new CultureInfo("en-US"))); // 1.23 (2 dp in every culture other than "nqo" and "nqo-GN")
Console.WriteLine((1.23456).ToString("F", new CultureInfo("nqo"))); // 1.235

More verbosely:

double number = 1.2345678;

Console.WriteLine($"Testing {number.GetType().FullName}");
Console.WriteLine($"value: {number}");
foreach (var culture in new string[] { "", "en-US", "fr-FR", "fa-IR", "nqo", "nqo-GN" } ) {
    var cultureinfo = new System.Globalization.CultureInfo(culture);
    string fformat = number.ToString("F", cultureinfo);
    Console.WriteLine($"{fformat} -- {cultureinfo.EnglishName} -- \"{cultureinfo.Name}\"");
}

Output:

Testing System.Double
value: 1.2345678
1.23 -- Invariant Language (Invariant Country) -- ""
1.23 -- English (United States) -- "en-US"
1,23 -- French (France) -- "fr-FR"
1/23 -- Persian (Iran) -- "fa-IR"
1.235 -- N'ko -- "nqo"
1.235 -- N'ko (Guinea) -- "nqo-GN"

For the sake of brevity I've only illustrated with one or two cultures for each type of output. I did try searching all cultures from CultureInfo.GetCultures(CultureTypes.AllCultures), and N'Ko (nqo or nqo-GN) is the only culture that gave 3 dp.

Note, this is not specific to the double type. You'll get similar results if you can also replace the declaration for number in the above code with any one of the following lines:

float number = 1.2345678f;
decimal number = new decimal(1.2345678);
int number = 1;
BigInteger number = new BigInteger(1);

After some research, I guess the issue is down to NumberFormatInfo.NumberDecimalDigits being set to 3 for the N'Ko culture, and 2 for every other culture. But I could not find anything actually stating that this was the case or why it would be the case.

Assert.AreEqual(2, new CultureInfo("en-US").NumberFormat.NumberDecimalDigits); // true (for every culture except N'Ko [nqo and nqo-GN])
Assert.AreEqual(3, new CultureInfo("nqo").NumberFormat.NumberDecimalDigits); // true (for N'Ko)

Wikipedia's article on the N'Ko alphabet lists the Unicode characters for N'ko numerals (߀‎߁‎߂‎߃‎߄‎߅‎߆‎߇‎߈‎߉‎) which begin at U+07C0, have a right-to-left directionality and were introduced in Unicode 5 (July 2006). It also has a section on "N'ko and computers", but currently has nothing relevant to this issue. N'Ko numerals do not appear to be used by the Fixed Point format.

Can anyone give some insight as to why Microsoft has chosen to format this culture's Fixed Point ("F") numbers with a different number of decimal places to every other one of the world's cultures?

I'm very curious to find out and could not find anything. Is there something special about how N'Ko groups numbers after the decimal place? Is the third decimal place required to display the second one correctly (e.g. due to ligatures or similar)? Or is it Microsoft keeping developers on their toes by making NumberDecimalDigits non-static? Or is it a bug? Or is there some other cultural reason?

like image 495
Qubei Avatar asked Apr 13 '18 01:04

Qubei


1 Answers

i've been digging through the .net code and found how the cultures are instantiated and created, and defaults are set in your windows. So you can see the defaults by going to your regional settings. If you choose nqo you will see that the default for No. digits after decimal is 3, hence .NET is returning you the 3 instead of 2.

See screenshot:

enter image description here

i know it is not really an answer on your how, but you now know why.

i was fascinated why and googled on it for a while, the only thing i found was this link, i used this term in google: "n'ko" numbers, and the second link is this http://www.languagesandnumbers.com/how-to-count-in-mandinka/en/mnk/ it is about mandinka numbers, a system used in guinea

then some more digging i found calculator:

https://github.com/ckairaba/calculator-nko

maybe by using that you will have some more info

like image 133
Ben Croughs Avatar answered Oct 07 '22 13:10

Ben Croughs