| | |
convert string to double, and result is string again
![]() |
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.
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
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads tree unlimited utility webservices windows






