将字符串转换为 int 而不会丢失开头的零 [英] Converting string to int without losing the zero in the beginning

查看:68
本文介绍了将字符串转换为 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 用于表示数学整数.数字 099999999 在数学上是完全相同的数字.

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 而不会丢失开头的零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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