Localized exponential notation?

2020-05-27 10:31发布

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:

  • 6.0221417930×1023

or more specifically E notation:

  • 6.0221417930E23

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.

2条回答
迷人小祖宗
2楼-- · 2020-05-27 11:24

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.

查看更多
祖国的老花朵
3楼-- · 2020-05-27 11:28

For Polish it should be 6,0221417930·1023.
I don't think CLDR mentioned by Serge (great answer BTW) is valid here. However, it is still the best source of information. Otherwise you would need to ask your translators to translate the pattern for you (which would require a comment with good explanation what you are up to).

查看更多
登录 后发表回答