局部指数表示法?

编程入门 行业动态 更新时间:2024-10-18 10:32:52
本文介绍了局部指数表示法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将数字转换为本地化的字符串.

对于整数和金钱值,这非常简单,因为字符串只是一系列数字和数字分组分隔符.例如:

  • 12 345 678 901(保加利亚)
  • 12.345.678.901(加泰罗尼亚语)
  • 12,345,678,901(英语)
  • 12,34,56,78,901(印地语)
  • 12.345.678.901(法语)
  • 12?345?678?901(普什图语)
  • 12'345'678'901(德语)

我使用Windows GetNumberFormat 函数以格式化整数(和 格式化货币值.

但是某些数字不能合理地用固定表示法表示,并且需要科学表示法:

  • 6.0221417930×10 23
  • 或更具体地 E符号:

    • 6.0221417930E23

    我如何获得科学计数法的本地化版本?

    我想我可以使用局部数字来构造它:

    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

    但是我不知道其他文化(除我以外的文化)是否使用 E 来进行求幂.

    解决方案

    据我所知,指数表示法不是Windows或.NET语言环境数据的一部分.但是, Unicode CLDR 可以帮助再次:其<numbers>部分包含您要查找的内容:

    /numbers/symbols/exponential表示E或给定区域性中的等价物.

    /numbers/scientificFormats/显示了幂模式.

    您需要下载压缩的核心CLDR数据并从common/main目录中提取您感兴趣的每种文化的文件.

    如果您希望能够支持所有区域性,则必须从所有区域性文件中收集相关信息,并将其打包到您自己的特定数据库中.并不是一件微不足道的工作,但是有可能.

    我快速浏览了几种不同文化的数据,例如en,fr,zh,ru,vi,ar:它们都包含相同的模式:#E0.看起来数据要么不准确(我很怀疑),要么您不必真正在乎:每个人都以相同的方式这样做,而您实际上并不在乎.

    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.

    解决方案

    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.

    更多推荐

    局部指数表示法?

    本文发布于:2023-11-29 20:48:52,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1647591.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:局部   指数

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!