• <small id='8RAyG'></small><noframes id='8RAyG'>

      1. <tfoot id='8RAyG'></tfoot>

        <legend id='8RAyG'><style id='8RAyG'><dir id='8RAyG'><q id='8RAyG'></q></dir></style></legend>
      2. <i id='8RAyG'><tr id='8RAyG'><dt id='8RAyG'><q id='8RAyG'><span id='8RAyG'><b id='8RAyG'><form id='8RAyG'><ins id='8RAyG'></ins><ul id='8RAyG'></ul><sub id='8RAyG'></sub></form><legend id='8RAyG'></legend><bdo id='8RAyG'><pre id='8RAyG'><center id='8RAyG'></center></pre></bdo></b><th id='8RAyG'></th></span></q></dt></tr></i><div id='8RAyG'><tfoot id='8RAyG'></tfoot><dl id='8RAyG'><fieldset id='8RAyG'></fieldset></dl></div>
        • <bdo id='8RAyG'></bdo><ul id='8RAyG'></ul>

        如何修复有小数分隔符问题的应用程序

        时间:2023-08-25
          <tbody id='qTsjZ'></tbody>
          <bdo id='qTsjZ'></bdo><ul id='qTsjZ'></ul>

          • <tfoot id='qTsjZ'></tfoot>
                <i id='qTsjZ'><tr id='qTsjZ'><dt id='qTsjZ'><q id='qTsjZ'><span id='qTsjZ'><b id='qTsjZ'><form id='qTsjZ'><ins id='qTsjZ'></ins><ul id='qTsjZ'></ul><sub id='qTsjZ'></sub></form><legend id='qTsjZ'></legend><bdo id='qTsjZ'><pre id='qTsjZ'><center id='qTsjZ'></center></pre></bdo></b><th id='qTsjZ'></th></span></q></dt></tr></i><div id='qTsjZ'><tfoot id='qTsjZ'></tfoot><dl id='qTsjZ'><fieldset id='qTsjZ'></fieldset></dl></div>

              1. <small id='qTsjZ'></small><noframes id='qTsjZ'>

                <legend id='qTsjZ'><style id='qTsjZ'><dir id='qTsjZ'><q id='qTsjZ'></q></dir></style></legend>
                  本文介绍了如何修复有小数分隔符问题的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这篇文章是关于 C# 和 .Net 的,但有些信息对其他技术很有价值.

                  从我记事起,我就一直遇到应用程序或游戏因解析十进制数的不同方式而崩溃的问题.它经常发生,从 CAD 应用程序、库到网页.不知道是无知还是缺乏见识,但真的很烦人.

                  有什么问题?.它告诉我390159851.超过一百万的数字很难阅读,数量级是多少?是 3900 万还是 390?

                1. Mirosoft XNA for Windows Phone 7 示例:有是一个非常简洁的类,可以解析 XML 文件以生成 XNA 动画

                  ///<总结>///从 xml 文件加载动画设置.///</总结>私人无效 LoadAnimiationFromXML(){XDocument 文档 =XDocument.Load("内容/纹理/AnimationsDefinition.xml");XName 名称 = XName.Get("定义");var 定义 = doc.Document.Descendants(name);if (animationDefinition.Attribute("Speed") != null){animation.SetFrameInvterval(TimeSpan.FromMilliseconds(double.Parse(animationDefinition.Attribute("Speed").Value)));}

                  double.Parse 抛出异常,一个简单的方法是使用 XmlConvert.ToDouble(); 或使用 InvariantCulture 解析.

                2. .Net 应用程序使用 CSV 文件将输入向量存储为 CSV - 也会抛出.

                3. 另一个在类中有一些解析的 .Net 应用程序 - throws.

                4. 那么我们该如何解决这个问题呢?

                  • 修复代码中的错误 - 只能使用可用的源代码且繁琐.
                  • 更改数据(CVS、XML 等) - 即使有可能,但对更改数据不太满意.
                  • 更改操作系统默认的小数点分隔符 - 不会发生.

                  还有其他方法可以解决这个问题吗?我可以让应用保持不变吗?就像在不同的环境中启动应用一样.

                  PS.我想运行应用程序,但我没有代码.

                  解决方案

                  正确设置Thread.CurrentThread.CurrentCulture就不会出现这样的问题.阅读此处如何编写与文化无关的代码.

                  如果您无权访问代码,则可以在具有预期文化集的用户帐户下运行应用程序.为了快速访问,您可以创建一个英语用户、一个德语用户、一个法语用户..

                  This post is about C# and .Net, but some info is valuable for other techonolgies.

                  Since I can remember, I've been having problems with apps or games that crash because of a different style of parsing decimal numbers. It happens very often, from CAD apps, libraries to web pages. I'm not sure whether it is ignorance or lack of knowledge, but it's really annoying.

                  What's the problem? Here is a wiki article about it, but it short:

                  Here is a map that shows what kind of decimal separator (decimal mark) is used around the world.

                  Decimal marks:

                  • Period — Blue
                  • Comma — Green
                  • Non-West-Arabic Numerals — Red
                  • Unknown — Grey

                  Most of the Europe, South America write 1 000 000,00 or 1000000,00 sometimes 1.000.000,00 as opposite to "imperial" (marked as blue) write 1,000,000.00

                  Let me just give you a few from all problems that I encoutered last month.

                  1. Number on webpages hard to read: Let's take one of the most viewed YT videos. It shows me 390159851. Number above one million are very hard to read, what's the order of magnitude? Is it 39 mln or 390?
                  2. Mirosoft XNA for Windows Phone 7 example: There is a very neat class that parse XML file to produce XNA animation

                    /// <summary>
                    /// Loads animation setting from xml file.
                    /// </summary>
                    private void LoadAnimiationFromXML()
                    {
                        XDocument doc = 
                                  XDocument.Load("Content/Textures/AnimationsDefinition.xml");
                        XName name = XName.Get("Definition");
                        var definitions = doc.Document.Descendants(name);
                    
                    
                            if (animationDefinition.Attribute("Speed") != null)
                            {
                                animation.SetFrameInvterval(TimeSpan.FromMilliseconds(
                                    double.Parse(animationDefinition.Attribute("Speed").Value)));
                            }
                    

                    double.Parse throws an exception, one simple soultion is to use XmlConvert.ToDouble(); or parse with InvariantCulture.

                  3. .Net app that use CSV files to store input vector as CSV - also throws.

                  4. Another .Net app that has some parsing inside the class - throws.

                  So how can we fix this?

                  • Fix the bug in code - possible only with avaible source code and tedious.
                  • Change the data (CVS, XML etc.) - even with possible, not very happy with mutating the data.
                  • Change the OS default decimal separator - not gonna happen.

                  Is there any other way to slove this? Can I make the app be invariant? Like starting the app in a different environment.

                  PS. I would like to run the app, but I don't have the code.

                  解决方案

                  Properly set Thread.CurrentThread.CurrentCulture and you wont have such problems. Read here how to write culture independent code.

                  EDIT: If you do not have access to the code, you can run the application under a user account which has the expected culture set. For quick access you could create an english user, a german user, a french user..

                  这篇关于如何修复有小数分隔符问题的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 WPF 应用程序中全局设置文化? 下一篇:.NET 3.5 中的 CultureInfo 类支持哪些文化?

                  相关文章

                  最新文章

                5. <legend id='04Uub'><style id='04Uub'><dir id='04Uub'><q id='04Uub'></q></dir></style></legend>
                    <bdo id='04Uub'></bdo><ul id='04Uub'></ul>
                    <i id='04Uub'><tr id='04Uub'><dt id='04Uub'><q id='04Uub'><span id='04Uub'><b id='04Uub'><form id='04Uub'><ins id='04Uub'></ins><ul id='04Uub'></ul><sub id='04Uub'></sub></form><legend id='04Uub'></legend><bdo id='04Uub'><pre id='04Uub'><center id='04Uub'></center></pre></bdo></b><th id='04Uub'></th></span></q></dt></tr></i><div id='04Uub'><tfoot id='04Uub'></tfoot><dl id='04Uub'><fieldset id='04Uub'></fieldset></dl></div>

                    <small id='04Uub'></small><noframes id='04Uub'>

                  1. <tfoot id='04Uub'></tfoot>