本文整理汇总了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);
}
}
}
示例2: AreEqual
static void AreEqual (string expected, Number actual, string msg)
{
expected = expected.Replace (" ", "").ToLower ().TrimStart ('0');
Assert.AreEqual (expected, actual.ToString (16), msg);
}
示例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;
}
示例4: VisitNumber
protected override Number VisitNumber(Number node)
{
visitedNumber = true;
Assert.IsTrue(node.ToString() == "0" || node.ToString() == "-0.0e0");
return base.VisitNumber(node);
}