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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
05is not an integer,5is. What you can do is format a long that holds5with 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?