如何反转以零C#结尾的数字 [英] How to reverse a number ending with zero C#

查看:87
本文介绍了如何反转以零C#结尾的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i低于代码



Hi,

i have below code

fiveDigNo=17660;

while (fiveDigNo!= 0)
{
   reverse = reverse * 10;
   reverse = reverse + fiveDigNo% 10;
   fiveDigNo= fiveDigNo/ 10;
}





我希望像06671一样反转。但我得到6671.



我的尝试:



反转功能。



I want to get reverse like 06671. But i am getting 6671.

What I have tried:

Reverse Function .

推荐答案

这是一样的。 06671 = 6671.这不是很明显吗?



如果你想获得06671,那不是关于你的号码,这是关于你呈现的方式数字作为字符串:

Int32.ToString方法(系统) [ ^ ],

Int32.ToString方法(字符串)(系统) [ ^ ],

标准数字格式字符串 [ ^ ],

自定义数字格式字符串 [ ^ ]。



严格来说,问题是反转一个数字没有正确定义。例如,如果您反转数字的八进制,十六进制数字等,您将得到不同的结果。所以,或者,您可以先通过 ToString 或以其他方式获取字符串,然后反转该字符串。



-SA
This is the same. 06671 = 6671. Isn't it obvious?

If you want to obtain "06671", it it not about your number, this is about the way you present the number as a string:
Int32.ToString Method (System)[^],
Int32.ToString Method (String) (System)[^],
Standard Numeric Format Strings[^],
Custom Numeric Format Strings[^].

Strictly speaking, the problem "reverse a number" wasn't correctly defined. For example, you would get different result if you "reverse" the number's octal, hexadecimal digits, and so on. So, you could, alternatively, simply get a string first, via ToString or in some other way, and then reverse that string.

—SA


'06671'' 6671'相同整数的两个不同的字符串表示。也就是说,如果您确实需要输出中的前导 0 ,那么您必须迟早将整数变量更改为字符串1。
'06671' and '6671' are two different string representations of the same integer number. That is, if you really need the leading 0 in the output then you have to change your integer variable into a string one, sooner or later.


数字06671和6671的数字相同。如果你想要一个像06671(字符串表示)的结果,你必须使用一个字符串并反转:

The numbers 06671 and 6671 are numerical identical. If you want a result like "06671" (a string representation) you have to use a string and reverse that:
string numString = fiveDigNo.ToString();
char[] charArray = numString.ToCharArray();
Array.Reverse(charArray);
string revString = new string(charArray);
// If you need the numeric value too:
int revNumber = Convert.ToInt32(revString);


这篇关于如何反转以零C#结尾的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆