i'm trying to convert numbers into localized strings.
For integers and money values it's pretty simple, since the string is just a series of digits and digit grouping separators. E.g.:
12 345 678 901
(Bulgarian)12.345.678.901
(Catalan)12,345,678,901
(English)12,34,56,78,901
(Hindi)12.345.678.901
(Frisian)12?345?678?901
(Pashto)12'345'678'901
(German)i use the Windows GetNumberFormat
function to format integers (and GetCurrencyFormat
to format money values).
But some numbers cannot be reasonably represented in fixed notation, and require scientific notation:
or more specifically E notation:
How can i get the localized version of scientific notation?
i suppose i could construct it using localized numbers:
6.0221417930E23
6,0221417930E23
6.0221417930e23
6·0221417930E23
6·0221417930e23
6,0221417930e23
6,,0221417930e23
6.0221417930E+23
6,0221417930E+23
6.0221417930e+23
6,0221417930e+23
6·0221417930E+23
6·0221417930e+23
6,,0221417930e+23
6.0221417930E23
6,0221417930E23
6.0221417930e23
6,0221417930e23
6·0221417930E23
6·0221417930e23
6,,0221417930e23
6.0221417930X10^23
6,0221417930X10^23
6.0221417930x10^23
6,0221417930x10^23
6·0221417930X10^23
6·0221417930x10^23
6,,0221417930x10^23
6.0221417930·10^23
6,0221417930·^23
6.0221417930.10^23
6,0221417930.10^23
6·0221417930·^23
6·0221417930.10^23
6,,0221417930.10^23
but i don't know if other cultures (cultures besides mine) use an E for exponentiation.
In exponential notation, a number usually is expressed as a coefficient between one and ten times an integral power of ten, the exponent. To express a number in exponential notation, write it in the form: c × 10n, where c is a number between 1 and 10 (e.g. 1, 2.5, 6.3, 9.8) and n is an integer (e.g. 1, -3, 6, -2).
Exponential notation is an alternative method of expressing numbers. Exponential numbers take the form an, where a is multiplied by itself n times. A simple example is 8=23=2×2×2. In exponential notation, a is termed the base while n is termed the power or exponent or index.
The Scientific format displays a number in exponential notation, replacing part of the number with E+n, in which E (exponent) multiplies the preceding number by 10 to the nth power. For example, a 2-decimal scientific format displays 12345678901 as 1.23E+10, which is 1.23 times 10 to the 10th power.
EE stands for Enter Exponent. It represents the expression *10^. For example, 2E-4 means 2*10-4. This notation has become the most used by mathematicians to input numbers in scientific notation.
To the best of my knowledge, exponentiation notation is not part of Windows or .NET locale data. However, the Unicode CLDR can help once again: Its <numbers>
sections contains what you are looking for:
/numbers/symbols/exponential
says E
or its equivalent in the given culture.
/numbers/scientificFormats/
shows the exponentiation pattern.
You'll need to download the zipped core CLDR data and extract the file for each culture you're interested in from the common/main
directory.
If you want to be able to support all cultures, you'll have to gather the relevant info from all culture files and pack it into your own specific DB. Not quite a trivial work but it's possible.
I gave a quick look to the data in a few very different cultures such as en, fr, zh, ru, vi, ar: They all contain the same pattern: #E0
. It looks like either the data is not accurate (I seriously doubt.) or you don't have to care really: Everybody does it the same way and you shouldn't actually care.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With