1

I have string 0000001.45 and I want to remove zero in front of the string and convert string to long. Is it possible to cast without loops. Have java some function for this.

1
  • 2
    So what have you tried already? Commented Apr 26, 2011 at 13:02

2 Answers 2

5

Well, the first thing that comes to mind:

 long result=(long)Double.parseDouble("000001.45");

The Double class can parse away the leading zeros, and the cast will convert to long.

Sign up to request clarification or add additional context in comments.

2 Comments

... which is "1" but, hey, that was the objective ;-)
Indeed. I don't know what the goal was - if it was to normalize it to 145, well, obviously other things would be done.
0

Have a look to the Long.parseLong() or equivalent classes for all the different Number types. I think you will need to parse it has a float or double then convert it to a long type.

1 Comment

Crash. Boom. Bang. (the input has a small, ugly dot) - but as you didn't suggest to use that method on the input - no downvote from my side ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.