zoukankan      html  css  js  c++  java
  • C# 科学计数法转换成数字

         /// <summary>
            /// 判断输入的数是否是科学计数法。如果是的话,就会将其换算成整数并且返回,否则就返回false。
            /// </summary>
            /// <param name="num"></param>
            /// <param name="CompleteNum"></param>
            /// <returns></returns>
            private bool ChkNum(string num, ref decimal CompleteNum)
            {
                bool result = false;
                bool resultSymbol = num.Contains("*");
                bool result0 = num.Contains("^");
                if ((resultSymbol == true) && (result0 == true))
                { //当数字中有*和^的时候,进行下面的判断
                    int IntSymbol = num.IndexOf("*");
                    int Symbol0 = num.IndexOf("^");
                    if (((Symbol0 - IntSymbol) == 3))
                    {//当*在^前面的时候
                        string numA = num.Substring(0, IntSymbol);//截取*号前面的数字(基数);
                        string numB = num.Substring(IntSymbol+1, Symbol0 - IntSymbol-1);//截取10;
                        string numC = num.Substring(Symbol0+1, num.Length - Symbol0-1);//获得幂次数
                        Regex regNum0 = new Regex(@"^(-|+)?d+(.d+)?$");
                        Regex regNum2 = new Regex(@"^-[1-9]d*$|^[1-9]d*$");
                        if ((regNum0.IsMatch(numA)) && (numB == "10") && (regNum2.IsMatch(numC)))
                        {
                            decimal dcNumA;
                            decimal.TryParse(numA,out dcNumA);
                            decimal dcNumC;
                            decimal.TryParse(numC, out dcNumC);//将幂次数转换成decimal类型
                            decimal zhengshu = 10;
                            if (dcNumC > 0)
                            {//当幂次数为整数的时候
                                for (int i = 0; i < dcNumC - 1; i++)
                                {
                                    zhengshu *= 10;
                                }
                            }
                            else
                            {//当幂次数为负数的时候
                                for (int i = 0; i < Math.Abs(dcNumC) + 1; i++) 
                                {
                                    zhengshu /= 10;
                                }
                            }
                            CompleteNum = dcNumA * zhengshu;
                            result = true;
                        }
                        else
                        {
                            result = false;
                        }
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }
                return result;
            }
  • 相关阅读:
    树系列学习--树的定义(-)
    idea live template高级知识, 进阶(给方法,类,js方法添加注释)(二)
    mysql 查询所有子节点的相关数据
    maven util 类 添加 service
    idea live template高级知识, 进阶(给方法,类,js方法添加注释)
    idea live template
    eclipse 好用的插件总结
    Spirng+SpringMVC+Maven+Mybatis+MySQL项目搭建
    Mac OS 的命令行 总结
    jsp,jquery,spring mvc 实现导出文件
  • 原文地址:https://www.cnblogs.com/vichin/p/6113999.html
Copyright © 2011-2022 走看看