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 而不会丢失开头的零
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
