本文介绍了将字符串解析为long,前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
长话短说(Java):
String input =0888880747;
long convert = Long.parseLong(输入);
转换的价值现在是:888880747
如何将 String
解析为 long
但保留领先优势零?
解决方案
你不能因为long没有前导零。一个long应该存储 。
你确定你甚至想要一个长整数吗?你想用它做什么?
Long story short (in Java):
String input= "0888880747;
long convert = Long.parseLong(input);
The value of convert is now: 888880747
How can I parse the String
to a long
but retain the leading zero?
解决方案
You cannot because a long does not have a leading zero. A long is supposed to store integers (the mathematical concept, not int
), i.e.
A string of characters like 05
is not an integer, 5
is. What you can do is format a long that holds 5
with a leading zero when you print it, see e.g. java.util.Formatter.
Are you sure you even want to have a long/an integer? What do you want to do with it?
这篇关于将字符串解析为long,前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!