当前位置: 首页>>代码示例>>C#>>正文


C# Number.ToString方法代码示例

本文整理汇总了C#中System.Number.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Number.ToString方法的具体用法?C# Number.ToString怎么用?C# Number.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Number的用法示例。


在下文中一共展示了Number.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpTolevel

        private static Number UpTolevel(Number num, int level)
        {
            if (num == null)
                return 0;

            switch (level)
            {
                case NumInt:
                {
                    if (num.TypeCode == NumberTypeCode.Int32)
                    {
                        return num;
                    }
                    return num;
                }

                case NumLong:
                {
                    if (num.TypeCode == NumberTypeCode.Int64)
                    {
                        return num;
                    }
                    return num;
                }

                case NumBigInteger:
                {
                    if (num.TypeCode == NumberTypeCode.BigInteger)
                    {
                        return num;
                    }
                    return BigInteger.Parse(num.ToString());
                }

                case NumBigDecimal:
                {
                    if (num.TypeCode == NumberTypeCode.BigDecimal)
                    {
                        return num;
                    }
                    return BigDecimal.Parse(num.ToString());
                }

                default:
                {
                    throw new ArgumentException("unsupported number level: " + level);
                }
            }
        }
开发者ID:tupunco,项目名称:Tup.Cobar4Net,代码行数:49,代码来源:ExprEvalUtils.cs

示例2: AreEqual

		static void AreEqual (string expected, Number actual, string msg)
		{
			expected = expected.Replace (" ", "").ToLower ().TrimStart ('0');
			Assert.AreEqual (expected, actual.ToString (16), msg);
		}
开发者ID:kazuki,项目名称:opencrypto.net,代码行数:5,代码来源:RecommendedCurveTest.cs

示例3: Format

        public static string Format(Number value,NumberFormatInfo format)
        {
            if (value == null)
                return String.Empty;

               string[] numberGroupFormats = format.NumberGroupFormat.Split(",");
               string formattedNumber = "";

               int wholeNumber = Math.Floor(Math.Abs(value));
               string wholeNumberString = wholeNumber.ToString();
               string decimalPartString = value.ToString().Substr(wholeNumberString.Length+1);

               int i = wholeNumberString.Length;
                int j = 0;

                while (i > 0)
                {
                    int groupSize = int.Parse(numberGroupFormats[j]);

                    // If there are more number group formats, get the next one, otherwise stick with this one until the end of the formatting
                    if (j < (numberGroupFormats.Length-1))
                        j++;

                    if (groupSize == 0)
                        groupSize = i + 1;

                    formattedNumber = wholeNumberString.Substring(i, i - groupSize) + formattedNumber;

                    if (i > groupSize)
                        formattedNumber = format.NumberSepartor + formattedNumber;

                    i = i - groupSize;
                }

                // Add decimal part
                bool neg = (value < 0);

                if (format.Precision > 0)
                {
                    // Add padding zeros

                    int paddingRequired = format.Precision - decimalPartString.Length;
                    for (int d = 0; d < paddingRequired; d++)
                    {
                        decimalPartString = decimalPartString + "0";
                    }

                    formattedNumber = formattedNumber + format.DecimalSymbol + decimalPartString;
                }

                // Format negative
                if (neg)
                {
                    switch (format.NegativeFormatCode)
                    {
                        case 0:
                            formattedNumber = "(" + formattedNumber + ")";
                            break;

                        case 2:
                            formattedNumber = "- " + formattedNumber;
                            break;
                        case 3:
                            formattedNumber = formattedNumber + "-";
                            break;
                        case 4:
                            formattedNumber = formattedNumber + " -";
                            break;
                        case 1:
                        default:
                            formattedNumber = "-" + formattedNumber;
                            break;
                    }
                }

                return formattedNumber;
        }
开发者ID:KostyaAfendikov,项目名称:SparkleXrm,代码行数:77,代码来源:NumberEx.cs

示例4: VisitNumber

 protected override Number VisitNumber(Number node)
 {
     visitedNumber = true;
     Assert.IsTrue(node.ToString() == "0" || node.ToString() == "-0.0e0");
     return base.VisitNumber(node);
 }
开发者ID:luiseduardohdbackup,项目名称:Linq.Parsers,代码行数:6,代码来源:JsonSyntaxVisitorTest.cs


注:本文中的System.Number.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。