Exemple #1
0
        public void MultiplyTest()
        {
            var a1 = new NumStr("60") * new NumStr("1.23");

            Assert.AreEqual(a1.ToString(), "73.8");
            a1 = new NumStr("96.2014") * new NumStr("6.3254");
            Assert.AreEqual(a1.ToString(), "608.51233556");
            a1 = new NumStr("0.25") * new NumStr("0.25");
            Assert.AreEqual(a1.ToString(), "0.0625");
            a1 = new NumStr("0.5") * new NumStr("60");
            Assert.AreEqual(a1.ToString(), "30");
            a1 = new NumStr("-0.5") * new NumStr("60");
            Assert.AreEqual(a1.ToString(), "-30");

            a1 = new NumStr("-98.023");
            a1 = a1 * a1;
            Assert.AreEqual(a1.ToString(), "9608.508529");

            var s = new OperationSpace(10, 16);

            a1 = new NumStr("7B", s) * new NumStr("3C", s);
            Assert.AreEqual(a1.ToString(), "1CD4");

            s  = new OperationSpace(4, 10);
            a1 = new NumStr("96.2014", s) * new NumStr("6.3254", s);
            Assert.AreEqual(a1.ToString(), "608.5123");
        }
Exemple #2
0
        public void UpdatePerformanceUI(Strategy strategy, Label winCount, Label looseCount,
                                        Label totalWin, Label totalLoss, Label largestWin, Label largestLoss, Label openCount,
                                        Label closedCount, Label lblOpenPL, Label repLbl)
        {
            PerformanceInfo spi = strategy.PerformanceInfo as PerformanceInfo;

            winCount.Text    = NumStr.ColonifyNumber(spi.winningPositionCount);
            looseCount.Text  = NumStr.ColonifyNumber(spi.loosingPositionCount);
            totalWin.Text    = NumStr.ColonifyNumber(spi.totalWin);
            totalLoss.Text   = NumStr.ColonifyNumber(spi.totalLoss);
            largestWin.Text  = NumStr.ColonifyNumber(spi.largestWin);
            largestLoss.Text = NumStr.ColonifyNumber(spi.largestLoss);
            openCount.Text   = NumStr.ColonifyNumber(spi.openPositions.Count);
            closedCount.Text = NumStr.ColonifyNumber(spi.closedPositions.Count);
            repLbl.Text      = NumStr.ColonifyWeight(spi.reputation);

            int openpl = 0;

            foreach (Position p in spi.openPositions)
            {
                openpl += p.GetProfitLoss();
            }

            lblOpenPL.Text = NumStr.ColonifyNumber(openpl);
        }
Exemple #3
0
        public void MinusTest()
        {
            var a1 = new NumStr("10000") - new NumStr("0.023");

            Assert.AreEqual(a1.ToString(), "9999.977");
            a1 = new NumStr("18.023") - new NumStr("9.023");
            Assert.AreEqual(a1.ToString(), "9");
            a1 = new NumStr("18.023") - new NumStr("9.344");
            Assert.AreEqual(a1.ToString(), "8.679");
            a1 = new NumStr("18.023") - new NumStr("18.023");
            Assert.AreEqual(a1.ToString(), "0");
            a1 = new NumStr("-18.023") - new NumStr("9.344");
            Assert.AreEqual(a1.ToString(), "-27.367");
            a1 = new NumStr("18.023") - new NumStr("-9.344");
            Assert.AreEqual(a1.ToString(), "27.367");
            a1 = new NumStr("-18.023") - new NumStr("-9.344");
            Assert.AreEqual(a1.ToString(), "-8.679");

            a1 = new NumStr("-98.023");
            a1 = a1 - a1;
            Assert.AreEqual(a1.ToString(), "0");

            var s = new OperationSpace(10, 16);

            a1 = new NumStr("7B", s) - new NumStr("3C", s);
            Assert.AreEqual(a1.ToString(), "3F");
        }
Exemple #4
0
        private static (object, int) ToObject(string str, int startPos, Type type)
        {
            startPos = DecodeSpace(str, startPos);
            var currChar = str[startPos];

            switch (currChar)
            {
            case '{':
                return(DecodeObject(str, type, startPos));

            case '[':
                return(DecodeArray(str, type, startPos));

            case '"':
                return(DecodeString(str, startPos));

            default:
                break;
            }
            if (NumStr.Contains(currChar))
            {
                return(DecodeNumber(str, type, startPos));
            }
            //true ,false ,null
            return(DecodeConst(str, type, startPos));
        }
Exemple #5
0
        public void PowerTest()
        {
            var a1 = new NumStr("-2") ^ new NumStr("29");

            Assert.AreEqual(a1.ToString(), "-536870912");
            a1 = new NumStr("0.6", new OperationSpace(12)) ^ new NumStr("23");
            Assert.AreEqual(a1.ToString(), "0.000007897302");
        }
Exemple #6
0
        private void refreshSignal()
        {
            double longWeight    = 0d;
            double shortWeight   = 0d;
            int    bestSignal    = SignalType.Neutral;
            int    providerCount = 0;

            foreach (ClientContextProvider provider in masterStrategy.ContextProviders)
            {
                double tempLong  = 0d;
                double tempShort = 0d;

                provider.GetSignalWeight(masterStrategy.ActiveInstrument, SignalType.Long, ref tempLong, ref tempShort);

                longWeight  += tempLong;
                shortWeight += tempShort;

                bestSignal += provider.GetBestSignal(masterStrategy.ActiveInstrument);
                providerCount++;
            }

            string longString  = " (" + NumStr.ColonifyWeight(longWeight) + ")";
            string shortString = " (" + NumStr.ColonifyWeight(shortWeight) + ")";

            double totalWeight = Math.Abs(longWeight) + Math.Abs(shortWeight);

            if (totalWeight == 0)
            {
                lblBuySignal.Text  = "N/A";
                lblSellSignal.Text = "N/A";
                return;
            }

            int longRatio  = (int)((longWeight / totalWeight) * 100);
            int shortRatio = (int)((shortWeight / totalWeight) * 100);

            lblBuySignal.Text  = longRatio.ToString() + "%" + longString;
            lblSellSignal.Text = shortRatio.ToString() + "%" + shortString;

            boldLabel(lblBuySignal, longRatio > shortRatio);
            boldLabel(lblSellSignal, shortRatio > longRatio);

            //all nodes say LONG
            if (bestSignal == providerCount)
            {
                lblBestSignal.Text = "BUY";
            }
            else if (bestSignal == -providerCount)
            {
                lblBestSignal.Text = "SELL";
            }
            else
            {
                lblBestSignal.Text = "NEUTRAL";
            }
        }
Exemple #7
0
 /// <summary>
 /// 用纯数字初始化
 /// </summary>
 /// <param name="num">数字</param>
 /// <param name="space">计算空间</param>
 /// <param name="maxDecimalPlaces">最大保留小数位数</param>
 public RealNum(NumStr num, OperationSpace space = null, int?maxDecimalPlaces = null)
 {
     this.Space            = space ?? (num != null ? num.Space : OperationSpace.DefaultSpace);
     this.MaxDecimalPlaces = maxDecimalPlaces.HasValue ? Math.Min(maxDecimalPlaces.Value, this.Space.DefaultMaxDecimalPlaces) : this.Space.DefaultMaxDecimalPlaces;
     if (num != null)
     {
         this.PositiveOrNegative = num.PositiveOrNegative;
         value = new NumStr(num, Space, MaxDecimalPlaces);
     }
 }
Exemple #8
0
        public void RightShiftTest()
        {
            var a1 = new NumStr("3.0345") >> 3;

            Assert.AreEqual(a1.ToString(), "3034.5");
            a1 = new NumStr("3") >> 3;
            Assert.AreEqual(a1.ToString(), "3000");
            a1 = new NumStr("1111.1234", null, 4) >> 5;
            Assert.AreEqual(a1.ToString(), "111112340");
        }
Exemple #9
0
        public void LeftShiftTest()
        {
            var a1 = new NumStr("3034.5") << 3;

            Assert.AreEqual(a1.ToString(), "3.0345");
            a1 = new NumStr("3") << 3;
            Assert.AreEqual(a1.ToString(), "0.003");
            a1 = new NumStr("1111.1234", null, 4) << 8;
            Assert.AreEqual(a1.ToString(), "0");
            a1 = new NumStr("1111.1234", null, 4) << 7;
            Assert.AreEqual(a1.ToString(), "0.0001");
        }
Exemple #10
0
        public void DivideTest()
        {
            var a1 = new NumStr("6.3") / new NumStr("2.3");

            Assert.AreEqual(a1.ToString(), "2.7391304347");
            a1 = new NumStr("6.3") / new NumStr("2.4");
            Assert.AreEqual(a1.ToString(), "2.625");
            a1 = new NumStr("63") / new NumStr("0.0023");
            Assert.AreEqual(a1.ToString(), "27391.3043478260");
            a1 = new NumStr("0.1") / new NumStr("991");
            Assert.AreEqual(a1.ToString(), "0.0001009081");

            a1 = new NumStr("-98.023");
            a1 = a1 / a1;
            Assert.AreEqual(a1.ToString(), "1");
        }
Exemple #11
0
        public void ModTest()
        {
            var a1 = new NumStr("6.3") % new NumStr("2.3");

            Assert.AreEqual(a1.ToString(), "1.7");
            a1 = new NumStr("789") % new NumStr("6");
            Assert.AreEqual(a1.ToString(), "3");
            a1 = new NumStr("-6") % new NumStr("3");
            Assert.AreEqual(a1.IsZero, true);
            a1 = new NumStr("-6") % new NumStr("-9");
            Assert.AreEqual(a1.ToString(), "-6");

            a1 = new NumStr("-98.023");
            a1 = a1 % a1;
            Assert.AreEqual(a1.ToString(), "0");
        }
Exemple #12
0
 /// <summary>
 /// 用纯数字初始化
 /// </summary>
 /// <param name="num">数字</param>
 /// <param name="space">计算空间</param>
 /// <param name="maxDecimalPlaces">最大保留小数位数</param>
 public RationalNum(NumStr num, OperationSpace space = null, int?maxDecimalPlaces = null)
     : base(num, space, maxDecimalPlaces)
 {
     space = space ?? num.Space;
     if (num.DecimalPlaces == 0)
     {
         numerator   = new NaturalNumStr(num, space);
         denominator = new NaturalNumStr(1, space);
     }
     else
     {
         numerator   = new NaturalNumStr(num.RemoveDecimalPoint(), space);
         denominator = new NaturalNumStr(1, space);
         denominator.RightShift(num.DecimalPlaces);
         FractionReduction();
     }
 }
Exemple #13
0
 /// <summary>
 /// 拷贝初始化
 /// </summary>
 /// <param name="num">原始对象</param>
 /// <param name="maxDecimalPlaces">最大保留小数位数</param>
 /// <param name="deep">是否为深拷贝</param>
 public RealNum(RealNum num, int?maxDecimalPlaces = null, bool deep = true)
     : base(num, maxDecimalPlaces)
 {
     if (num.value != null)
     {
         if (deep)
         {
             value = new NumStr(num.value, null, true);
         }
         else
         {
             value = num.value;
         }
     }
     else
     {
         value = null;
     }
 }
Exemple #14
0
        private void updateStats()
        {
            int trend = commonContext.MarketMeter.GetMarketTrend(activeInstrument, activeTimeFrame);
            int vol   = commonContext.MarketMeter.GetMarketVolatility(activeInstrument, activeTimeFrame);

            //SimpleRange bsentiment = commonContext.MarketMeter.GetMarketSentiment(activeInstrument.BaseCurrency);
            //SimpleRange qsentiment = commonContext.MarketMeter.GetMarketSentiment(activeInstrument.QuoteCurrency);

            setLabel(lblMarketTrend, trend);
            setLabel(lblMarketVolatility, vol);
            //setLabel(lblMarketBaseSentiment, bsentiment);
            //setLabel(lblMarketQuoteSentiment, qsentiment);
            setLabel(lblCurrentTick, NumStr.ColonifyNumber(commonContext.MarketWatch.CurrentTickIndex));
            setLabel(lblOpenPositionCount, NumStr.ColonifyNumber(commonContext.DefaultAccount.TotalPositionCount -
                                                                 commonContext.DefaultAccount.ClosedPositionCount));
            setLabel(lblClosedPositionCount, NumStr.ColonifyNumber(commonContext.DefaultAccount.ClosedPositionCount));
            setLabel(lblStrategyCount, NumStr.ColonifyNumber(commonContext.StrategyRepository.StrategyCount));
            setLabel(lblSignalCount, NumStr.ColonifyNumber(commonContext.IndicatorRepository.IndicatorCount));
            setLabel(lblStrategyDeleteCount, NumStr.ColonifyNumber(commonContext.StrategyRepository.DeleteCounter));
            setLabel(lblTickQueueSize, NumStr.ColonifyNumber(commonContext.MarketWatch.TickQueueSize));
        }
Exemple #15
0
        public void PlusTest()
        {
            var a1 = new NumStr("21000") + new NumStr("3.277");

            Assert.AreEqual(a1.ToString(), "21003.277");
            a1 = new NumStr("98.023") + new NumStr("3.977");
            Assert.AreEqual(a1.ToString(), "102");
            a1 = new NumStr("-98.023") + new NumStr("3.977");
            Assert.AreEqual(a1.ToString(), "-94.046");
            a1 = new NumStr("98.023") + new NumStr("-3.977");
            Assert.AreEqual(a1.ToString(), "94.046");
            a1 = new NumStr("-98.023") + new NumStr("-3.977");
            Assert.AreEqual(a1.ToString(), "-102");

            a1 = new NumStr("-98.023");
            a1 = a1 + a1;
            Assert.AreEqual(a1.ToString(), "-196.046");

            var s = new OperationSpace(10, 16);

            a1 = new NumStr("7B", s) + new NumStr("3C", s);
            Assert.AreEqual(a1.ToString(), "B7");
        }
Exemple #16
0
        public void SpaceConversionTest()
        {
            var a1 = new NumStr("76.25", new OperationSpace(2, 10));

            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 2)).ToString(), "1001100.01");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 8)).ToString(), "114.2");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 10)).ToString(), "76.25");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 16)).ToString(), "4C.4");
            a1 = new NumStr("1001100.01", new OperationSpace(2, 2));
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 2)).ToString(), "1001100.01");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 8)).ToString(), "114.2");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 10)).ToString(), "76.25");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 16)).ToString(), "4C.4");
            a1 = new NumStr("114.2", new OperationSpace(2, 8));
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 2)).ToString(), "1001100");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 8)).ToString(), "114.2");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 10)).ToString(), "76.24");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 16)).ToString(), "4C.3D");
            a1 = new NumStr("4C.4", new OperationSpace(2, 16));
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 2)).ToString(), "1001100");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 8)).ToString(), "114.17");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 10)).ToString(), "76.24");
            Assert.AreEqual(a1.ChangeOperationSpace(new OperationSpace(2, 16)).ToString(), "4C.4");
        }
Exemple #17
0
        /// <summary>
        /// 金额小写转中文大写。
        /// 整数支持到万亿;小数部分支持到分(超过两位将进行Banker舍入法处理)
        /// </summary>
        /// <param name="Num">需要转换的双精度浮点数</param>
        /// <returns>转换后的字符串</returns>
        public static string ToChineseNumberUpper(double Num)
        {
            String[] Ls_ShZ   = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" };
            String[] Ls_DW_Zh = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万" };
            String[] Num_DW   = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万" };
            String[] Ls_DW_X  = { "角", "分" };

            Boolean iXSh_bool  = false; //是否含有小数,默认没有(0则视为没有)
            Boolean iZhSh_bool = true;  //是否含有整数,默认有(0则视为没有)
            Boolean negative   = false;

            string NumStr;            //整个数字字符串
            string NumStr_Zh;         //整数部分
            string NumSr_X = "";      //小数部分
            string NumStr_DQ;         //当前的数字字符
            string NumStr_R = "";     //返回的字符串

            Num = Math.Round(Num, 2); //四舍五入取两位

            //各种非正常情况处理
            if (Num < 0)
            {
                Num      = Math.Abs(Num);
                negative = true;
                //return "无效值";
            }
            if (Num > 9999999999999.99)
            {
                return("无效值");
            }
            if (Num == 0)
            {
                return(Ls_ShZ[0]);
            }

            //判断是否有整数
            if (Num < 1.00)
            {
                iZhSh_bool = false;
            }

            NumStr = Num.ToString();

            NumStr_Zh = NumStr; //默认只有整数部分
            if (NumStr_Zh.Contains("."))
            {                   //分开整数与小数处理
                NumStr_Zh = NumStr.Substring(0, NumStr.IndexOf("."));
                NumSr_X   = NumStr.Substring((NumStr.IndexOf(".") + 1), (NumStr.Length - NumStr.IndexOf(".") - 1));
                iXSh_bool = true;
            }


            if (NumSr_X == "" || int.Parse(NumSr_X) <= 0)
            {//判断是否含有小数部分
                iXSh_bool = false;
            }

            if (iZhSh_bool)
            {                                         //整数部分处理
                NumStr_Zh = Reversion_Str(NumStr_Zh); //反转字符串

                for (int a = 0; a < NumStr_Zh.Length; a++)
                {//整数部分转换
                    NumStr_DQ = NumStr_Zh.Substring(a, 1);
                    if (int.Parse(NumStr_DQ) != 0)
                    {
                        NumStr_R = Ls_ShZ[int.Parse(NumStr_DQ)] + Ls_DW_Zh[a] + NumStr_R;
                    }
                    else if (a == 0 || a == 4 || a == 8)
                    {
                        if (NumStr_Zh.Length > 8 && a == 4)
                        {
                            continue;
                        }
                        NumStr_R = Ls_DW_Zh[a] + NumStr_R;
                    }
                    else if (int.Parse(NumStr_Zh.Substring(a - 1, 1)) != 0)
                    {
                        NumStr_R = Ls_ShZ[int.Parse(NumStr_DQ)] + NumStr_R;
                    }
                }
                if (negative)
                {
                    NumStr_R = "负" + NumStr_R;
                }
                if (!iXSh_bool)
                {
                    return(NumStr_R + "整");
                }

                //NumStr_R += "零";
            }

            for (int b = 0; b < NumSr_X.Length; b++)
            {//小数部分转换
                NumStr_DQ = NumSr_X.Substring(b, 1);
                if (int.Parse(NumStr_DQ) != 0)
                {
                    NumStr_R += Ls_ShZ[int.Parse(NumStr_DQ)] + Ls_DW_X[b];
                }
                else if (b != 1 && iZhSh_bool)
                {
                    NumStr_R += Ls_ShZ[int.Parse(NumStr_DQ)];
                }
            }
            if (negative)
            {
                NumStr_R = "负" + NumStr_R;
            }
            return(NumStr_R);
        }
Exemple #18
0
        /// <summary>
        /// 金额小写转中文大写。
        /// 整数支持到万亿;小数部分支持到分(超过两位将进行Banker舍入法处理)
        /// </summary>
        /// <param name="Num">需要转换的双精度浮点数</param>
        /// <returns>转换后的字符串</returns>
        public static String NumGetStr(this Double Num)
        {
            Boolean iXSh_bool  = false; //是否含有小数,默认没有(0则视为没有)
            Boolean iZhSh_bool = true;  //是否含有整数,默认有(0则视为没有)

            string NumStr;              //整个数字字符串
            string NumStr_Zh;           //整数部分
            string NumSr_X = "";        //小数部分
            string NumStr_DQ;           //当前的数字字符
            string NumStr_R = "";       //返回的字符串

            Num = Math.Round(Num, 2);   //四舍五入取两位

            //各种非正常情况处理
            if (Num < 0)
            {
                return("不转换欠条");
            }
            if (Num > 9999999999999.99)
            {
                return("很难想象谁会有这么多钱!");
            }
            if (Num == 0)
            {
                return(Ls_ShZ[0]);
            }

            //判断是否有整数
            if (Num < 1.00)
            {
                iZhSh_bool = false;
            }

            NumStr = Num.ToString();

            NumStr_Zh = NumStr; //默认只有整数部分
            if (NumStr_Zh.Contains("."))
            {                   //分开整数与小数处理
                NumStr_Zh = NumStr.Substring(0, NumStr.IndexOf("."));
                NumSr_X   = NumStr.Substring((NumStr.IndexOf(".") + 1), (NumStr.Length - NumStr.IndexOf(".") - 1));
                iXSh_bool = true;
            }


            if (NumSr_X == "" || int.Parse(NumSr_X) <= 0)
            {//判断是否含有小数部分
                iXSh_bool = false;
            }

            if (iZhSh_bool)
            {                                                       //整数部分处理
                NumStr_Zh = string.Join("", (NumStr_Zh).Reverse()); //反转字符串

                for (int a = 0; a < NumStr_Zh.Length; a++)
                {//整数部分转换
                    NumStr_DQ = NumStr_Zh.Substring(a, 1);
                    if (int.Parse(NumStr_DQ) != 0)
                    {
                        NumStr_R = Ls_ShZ[int.Parse(NumStr_DQ)] + Ls_DW_Zh[a] + NumStr_R;
                    }
                    else if (a == 0 || a == 4 || a == 8)
                    {
                        if (NumStr_Zh.Length > 8 && a == 4)
                        {
                            continue;
                        }
                        NumStr_R = Ls_DW_Zh[a] + NumStr_R;
                    }
                    else if (int.Parse(NumStr_Zh.Substring(a - 1, 1)) != 0)
                    {
                        NumStr_R = Ls_ShZ[int.Parse(NumStr_DQ)] + NumStr_R;
                    }
                }

                if (!iXSh_bool)
                {
                    return(NumStr_R + "整");
                }

                //NumStr_R += "零";
            }

            for (int b = 0; b < NumSr_X.Length; b++)
            {//小数部分转换
                NumStr_DQ = NumSr_X.Substring(b, 1);
                if (int.Parse(NumStr_DQ) != 0)
                {
                    NumStr_R += Ls_ShZ[int.Parse(NumStr_DQ)] + Ls_DW_X[b];
                }
                else if (b != 1 && iZhSh_bool)
                {
                    NumStr_R += Ls_ShZ[int.Parse(NumStr_DQ)];
                }
            }

            return(NumStr_R);
        }
Exemple #19
0
 public override int GetHashCode()
 {
     return(Num + NumStr.GetHashCode() + Ttype.GetHashCode() + Axis * 100);
 }
Exemple #20
0
 /// <summary>
 /// 用纯数字初始化(小数部分会被截断)
 /// </summary>
 /// <param name="num">数字</param>
 /// <param name="space">计算空间</param>
 public IntegerNum(NumStr num, OperationSpace space = null)
     : base(new NaturalNumStr(num, false), space, 0)
 {
     PositiveOrNegative = num.PositiveOrNegative;
 }
Exemple #21
0
        /// <summary>
        /// 金额转大写
        /// </summary>
        /// <param name="Num"></param>
        /// <returns></returns>
        public static string NumGetStr(double Num)
        {
            string[] DX_SZ   = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" }; //大写数字
            string[] DX_DW   = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万" };
            string[] DX_XSDS = { "角", "分" };                                              //大些小数单位
            if (Num == 0)
            {
                return(DX_SZ[0]);
            }

            Boolean IsXS_bool = false; //是否小数

            string NumStr;             //整个数字字符串
            string NumStr_Zs;          //整数部分
            string NumSr_Xs = "";      //小数部分
            string NumStr_R = "";      //返回的字符串


            NumStr    = Num.ToString();
            NumStr_Zs = NumStr;
            if (NumStr_Zs.Contains("."))
            {
                NumStr    = Math.Round(Num, 2).ToString();
                NumStr_Zs = NumStr.Substring(0, NumStr.IndexOf("."));
                NumSr_Xs  = NumStr.Substring((NumStr.IndexOf(".") + 1), (NumStr.Length - NumStr.IndexOf(".") - 1));
                IsXS_bool = true;
            }

            int     k      = 0;
            Boolean IsZeor = false;                    //整数中间连续0的情况

            for (int i = 0; i < NumStr_Zs.Length; i++) //整数
            {
                int j = int.Parse(NumStr_Zs.Substring(i, 1));
                if (j != 0)
                {
                    NumStr_R += DX_SZ[j] + DX_DW[NumStr_Zs.Length - i - 1];
                    IsZeor    = false; //没有连续0
                }
                else if (j == 0)
                {
                    k++;
                    if (!IsZeor && !(NumStr_Zs.Length == i + 1)) //等于0不是最后一位,连续0取一次
                    {
                        //有问题
                        if (NumStr_Zs.Length - i - 1 >= 4 && NumStr_Zs.Length - i - 1 <= 6)
                        {
                            NumStr_R += DX_DW[4] + "零";
                        }
                        else
                        if (NumStr_Zs.Length - i - 1 > 7)
                        {
                            NumStr_R += DX_DW[8] + "零";
                        }
                        else
                        {
                            NumStr_R += "零";
                        }

                        IsZeor = true;
                    }

                    if (NumStr_Zs.Length == i + 1)//  等于0且是最后一位 变成 XX元整
                    {
                        NumStr_R += DX_DW[NumStr_Zs.Length - i - 1];
                    }
                }
            }
            if (NumStr_Zs.Length > 2 && k == NumStr_Zs.Length - 1)
            {
                NumStr_R = NumStr_R.Remove(NumStr_R.IndexOf('零'), 1); //比如1000,10000元整的情况下 去0
            }
            if (!IsXS_bool)
            {
                return(NumStr_R + "整");            //如果没有小数就返回
            }
            else
            {
                for (int i = 0; i < NumSr_Xs.Length; i++)
                {
                    int j = int.Parse(NumSr_Xs.Substring(i, 1));
                    NumStr_R += DX_SZ[j] + DX_XSDS[NumSr_Xs.Length - i - 1];
                }
            }

            return(NumStr_R);
        }
Exemple #22
0
 /// <summary>
 /// 默认构造函数,初始化为0
 /// </summary>
 public RealNum()
 {
     value = new NumStr(0, Space, MaxDecimalPlaces);
 }