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.
-
2So what have you tried already?Oliver Charlesworth– Oliver Charlesworth2011-04-26 13:02:25 +00:00Commented Apr 26, 2011 at 13:02
Add a comment
|
2 Answers
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.
2 Comments
Andreas Dolk
... which is "1" but, hey, that was the objective ;-)
Joseph Ottinger
Indeed. I don't know what the goal was - if it was to normalize it to 145, well, obviously other things would be done.
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
Andreas Dolk
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 ;)