I'm quite sure 5 mins of google will solve this problem for you.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
Have this as example.......
class doubconv
{
public static void main(String args[])
{
String code="00000000001";
double dbl=Double.parseDouble(code);
double dbl1=dbl+1;
String result=dbl1+"";
System.out.println(result);
}
}
vinod_javas
Practically a Posting Shark
871 posts since Feb 2007
Reputation Points: 119
Solved Threads: 7
Awwwwwwwww, but how do I get the leading zeroes back?! Will be his next post.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
if you have better way more than this means please show your solutions also. it will be really useful
(for adding zero)
class doubconv
{
public static void main(String args[])
{
String code="00000000001";
int leng=code.length();
int cnt=0;
for(int j=0;j
vinod_javas
Practically a Posting Shark
871 posts since Feb 2007
Reputation Points: 119
Solved Threads: 7
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
I am almost sure that you are doing all this for display purposes. If so, then why not just use the formatting provided by the printf method.
int i = 1;
System.out.printf("%010d%n", i);
i += 10;
System.out.printf("%010d%n", i);
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
That or use NumberFormat.
To any sane person (and a computer in that regard is a sane person) the leading zeros are utterly unimportant, a darned nuisance even, and thus stripped and ignored.
None of you except sos realised that apparently. None of you took the trouble to actually look at how numbers are represented in a computer, and thus realised that there are no leading zeros anywhere.
The number is stored as a series of bits representing a number, NOT a string, and a number never has leading zeros.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
That or use NumberFormat.
To any sane person (and a computer in that regard is a sane person) the leading zeros are utterly unimportant, a darned nuisance even, and thus stripped and ignored.
None of you except sos realised that apparently. None of you took the trouble to actually look at how numbers are represented in a computer, and thus realised that there are no leading zeros anywhere.
The number is stored as a series of bits representing a number, NOT a string, and a number never has leading zeros.
Obviously my posts were facetious. This idoicy of storing a double as a string and converting back and forth to do math with it is just that, idoicy.Obviously you simply use (and store) a double as a double and format the output as you want it, when it comes time to produce output, and not before. Anything else, is, as already stated, idiocy.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494