听起来你只是想要:
int value = 2590123;
string text = value.ToString();
Run Code Online (Sandbox Code Playgroud)
这将自动使用基数10 ...至少在我所知道的所有文化中.如果你真的想确定,请使用不变文化:
string text = value.ToString(CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
请注意,当您使用某种形式的单独"数字"(例如字符串表示)来讨论某些表示时,基本概念才有意义.一个纯数字没有基数 - 如果你有16个苹果,那就像你有0x10苹果一样.
编辑:或者如果你想编写一个方法来返回数字序列作为整数,最不重要的是:
// Note that this won't give pleasant results for negative input
static IEnumerable<int> GetDigits(int input)
{
// Special case...
if (input == 0)
{
yield return 0;
yield break;
}
while (input != 0)
{
yield return input % 10;
input = input / 10;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
167 次 |
| 最近记录: |