简体   繁体   English

没有“ E”的双重解析科学计数法

[英]Double parse scientific notation without 'E'

There are plenty of answered questions about how to parse a number in scientific notation in C#: 关于如何在C#中以科学计数法解析数字,有很多已回答的问题:

Double.Parse("1.234567E-06", System.Globalization.NumberStyles.Float);

But, is there a built in function to parse a number like this without introducing manually a 'E'? 但是,是否有内置函数可以解析这样的数字而无需手动引入“ E”?

2.8095-9

EDIT: here is the method to insert an "E" and parse the string to double 编辑:这是插入“ E”并将字符串解析为双精度的方法

  private double RecExp(string myString)
    {
        if (myString.Trim() == string.Empty) { return 0; }
        if (myString.Contains('-'))
        {
            if (myString.ToUpper().Contains("E") == false)
            {
                myString= myString.Insert(myString.IndexOf('-'), "E");
            }
        }
        return Double.Parse(myString, NumberStyles.Float);
    }

Just as clarification, I wasn't asking for providing this piece of code, I was asking if there exists a built in way of doing this. 澄清一下,我不是在要求提供这段代码,而是在询问是否存在内置的实现方法。

No, you need to write a few lines of code. 不,您需要编写几行代码。 I am assuming that anyone using stackoverflow knows hows to use string.split and float.parse. 我假设任何使用stackoverflow的人都知道如何使用string.split和float.parse。

Otherwise if the real questions is “teach me to program” or “do my homework” please vote to close your questions as too board. 否则,如果真正的问题是“教我编程”或“做我的功课”,请投票表决以结束您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM