我遇到一个问题:“如何将数字反转为整数而不是字符串?” 谁能帮我找出答案吗?反转应反转数字的十进制数字,即以10为底。
应该这样做:
int n = 12345; int left = n; int rev = 0; while(Convert.ToBoolean(left)) // instead of left>0 , to reverse signed numbers as well { r = left % 10; rev = rev * 10 + r; left = left / 10; //left = Math.floor(left / 10); } Console.WriteLine(rev);