convert string to double, and result is string again

Reply

Join Date: Apr 2007
Posts: 34
Reputation: onsir is an unknown quantity at this point 
Solved Threads: 1
onsir onsir is offline Offline
Light Poster

convert string to double, and result is string again

 
0
  #1
Aug 20th, 2007
hello
how to convert string to double, and result is string.
example ;
String code =00000000001;
Double plus =code + 1;
String result =plus; // and result is 0000000002

thanks
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: convert string to double, and result is string again

 
0
  #2
Aug 20th, 2007
I'm quite sure 5 mins of google will solve this problem for you.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 34
Reputation: onsir is an unknown quantity at this point 
Solved Threads: 1
onsir onsir is offline Offline
Light Poster

Re: convert string to double, and result is string again

 
0
  #3
Aug 20th, 2007
please give me a link, thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 871
Reputation: vinod_javas is an unknown quantity at this point 
Solved Threads: 7
vinod_javas's Avatar
vinod_javas vinod_javas is offline Offline
Practically a Posting Shark

Re: convert string to double, and result is string again

 
0
  #4
Aug 20th, 2007
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);


}
}
Adios,

Vinod......
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,343
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 251
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: convert string to double, and result is string again

 
0
  #5
Aug 20th, 2007
Awwwwwwwww, but how do I get the leading zeroes back?! Will be his next post.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 871
Reputation: vinod_javas is an unknown quantity at this point 
Solved Threads: 7
vinod_javas's Avatar
vinod_javas vinod_javas is offline Offline
Practically a Posting Shark

Re: convert string to double, and result is string again

 
0
  #6
Aug 21st, 2007
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<leng;j++)
{
char c=code.charAt(j);
if(c=='0')
{
cnt++;

}
else
{
break;
}
System.out.println(cnt);
}
String si="";
for (int k=0;k<cnt ;k++ )
{
si=si+"0";
}
double dbl=Double.parseDouble(code);
double dbl1=dbl+1;

String result=si+dbl1+"";

System.out.println(result);


}
}
Last edited by vinod_javas; Aug 21st, 2007 at 2:59 am.
Adios,

Vinod......
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 45
Reputation: satish.paluvai is an unknown quantity at this point 
Solved Threads: 1
satish.paluvai satish.paluvai is offline Offline
Light Poster

Re: convert string to double, and result is string again

 
0
  #7
Aug 21st, 2007
hello,
String s1=new String("0000001");
Double d=new Double(s1);
double d1=d.doubleValue();
s1=d1+"";
if u solve ur problem plz give a reply. i hopw u will solve ur problem by using this simple logic
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,343
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 251
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: convert string to double, and result is string again

 
0
  #8
Aug 21st, 2007
Repeat reply #5.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: convert string to double, and result is string again

 
0
  #9
Aug 26th, 2007
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.

  1. int i = 1;
  2. System.out.printf("%010d%n", i);
  3. i += 10;
  4. System.out.printf("%010d%n", i);
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: convert string to double, and result is string again

 
0
  #10
Aug 26th, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC