當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。