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 而不会丢失开头的零
基础教程推荐
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
