| | |
convert string to double, and result is string again
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
----------------------------------------------
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
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);
}
}
(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......
Vinod......
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
----------------------------------------------
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
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.
Java Syntax (Toggle Plain Text)
int i = 1; System.out.printf("%010d%n", i); i += 10; System.out.printf("%010d%n", i);
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
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.
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.
![]() |
Similar Threads
- Escape Sequences or Accepting Double Quotes in String Constants (Visual Basic 4 / 5 / 6)
- convert char* to double (C++)
- Please Help Stuck Need Help Asap!!! (Java)
- string to long and string to double in c (C)
- string to double (C++)
- convert from 'ref double[]' to 'ref object' (C#)
- no matching function for call to 'strcmp(std::string&, std::string&)' (C++)
- How to write FNVAL functions (Java)
Other Threads in the Java Forum
- Previous Thread: calling another function in nested class
- Next Thread: Getting mouse coordinates from MouseListener
Views: 4766 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android api apple applet application arguments array arrays automation binary block bluetooth chat class classes client code compile component database developmenthelp draw eclipse encode error event exception file fractal freeze game gameprogramming givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number object online oracle print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing system template test textfields threads time title transfer tree tutorial-sample update windows working






