Converting string to int without losing the zero in the beginning(将字符串转换为 int 而不会丢失开头的零)
问题描述
我尝试了 int.parse, 和 convert class 将字符串转换为 int.
I tried int.parse, and convert class to convert a string to int.
当我正在转换时.我一开始就输掉了我不想要的 0.
While I'm converting. I'm losing the 0 in the beginning which i don't want.
例如:09999 变成 9999 - 我不想要这个.
Ex : 09999 becomes 9999 - I don't want this.
我想保持原样.
我该怎么做?
推荐答案
你不能.int 用于表示数学整数.数字 09999 和 9999 在数学上是完全相同的数字.
You cannot. An int is meant to represent a mathematical integer. The numbers 09999 and 9999 are exactly the same number, mathematically.
也许这里有一个不同的问题.为什么需要这样做?也许有更好的方法来做你想做的事.
Perhaps there is a different problem here. Why do you need to do this? Maybe there's a better way to do what you want to do.
这篇关于将字符串转换为 int 而不会丢失开头的零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将字符串转换为 int 而不会丢失开头的零
基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
