取个位
int i = 1234567;
Response.Write((i-i / 10* 10));
//实际运行
//1234567 - (1234567/10 = 123456 *10= 1234560 )
//1234567-1234560
依次类推
public void 取个位数到百位数()
{
int i = 1234567;
for (int k = 1; k <= 3; k++)
{
//取个位
//System.Diagnostics.Trace.WriteLine( (i - i / 10 * 10) );
int n = (int)Math.Pow(10, k);
//取第N位
System.Diagnostics.Trace.WriteLine( ( i - i / n * n)*10/n );
}
}
/// <summary>
/// 求num在n位上的数字,取个位,取十位
/// </summary>
/// <param name="num">正整数</param>
/// <param name="n">所求数字位置(个位 1,十位 2 依此类推)</param>
public int FindNum(int num, int n)
{
//int power = 1;
//for (int i = 0; i < n; i++)
//{
// power *= 10;
//}
int power = (int)Math.Pow(10, n);
return (num - num / power * power) * 10 / power;
}