aspose file tools*
The moose likes Beginning Java and the fly likes using doubleToString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using doubleToString" Watch "using doubleToString" New topic
Author

using doubleToString

Pip Vo
Greenhorn

Joined: Jul 18, 2001
Posts: 12
Hi Ranchers:
Am having problems with data type determination
and conversion.
I want to put all non double tokens into my name1 array and all doubles into data1 array.
CODE:

I get the following error message:
cannot resolve symbol
symbol : method doubleToString (double,int,int)
I got this method from Sun's page, but there's
not a whole lot written about it. Maybe I need an
example of it being used. Would appreciate
any advice. Thank you!
Pip
Edited by Dave to put code in code tags
[ February 12, 2002: Message edited by: Dave Vick ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Pip
Do you a have a method named doubleToString with the signature of (double,int,int)? It looks like the compiler can't find it.
You need to have the method in you class in order to call it.


Dave
Pip Vo
Greenhorn

Joined: Jul 18, 2001
Posts: 12
Thank you. I decided to use a different converter:
name1[count2] = String.valueOf(data1[count1])
so my code is now:
import java.io.*;
import java.util.StringTokenizer;
public class catV2
{
static String temp1[] = new String[100];
static String name1[] = new String[100];
static double data1[] = new double[100];
static int count1 = 0;
static int count2 = 0;
static int i = 0; static int j = 0;
static int k = 0;
public static void main (String args[])
{
String line;

try
{
BufferedReader br = new BufferedReader
(new FileReader(args[i]));
while ((line = br.readLine()) != null)
{
System.out.println("CURRENT LINE: " +line);
StringTokenizer st = new StringTokenizer(line);
try
{
while (st.hasMoreTokens())
{
data1[count1] = Double.parseDouble(st.nextToken());
System.out.println("DATA: " +data1[count1]);
count1++;
j++;
} // end while
} // end inner try
catch (NumberFormatException e)
{System.out.println("ERROR: NOT DOUBLE");
//name1[count2] = double.toString(data1[count1]);
name1[count2] = String.valueOf(data1[count1]);
System.out.println("NAME: " +name1[count2]); count2++;}
count2++;
k++;
//}
} // end while
} // end try
catch(IOException e)
{System.err.println("ERROR: " +e);}

}
}
This compiles fine, but gives me weird results.
My sample file content:
123 ABC111
456 DEF222
789 GHI333
GR8 111111
Results:
reisling>>javac catV2.java
reisling>>java catV2 text.txt
CURRENT LINE: 123 ABC111
DATA: 123.0
ERROR: NOT DOUBLE
NAME: 0.0
CURRENT LINE: 456 DEF222
DATA: 456.0
ERROR: NOT DOUBLE
NAME: 0.0
CURRENT LINE: 789 GHI333
DATA: 789.0
ERROR: NOT DOUBLE
NAME: 0.0
CURRENT LINE: GR8 111111
ERROR: NOT DOUBLE
NAME: 0.0
Why is 123 not a double? Please help. Thank you.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Pip
the value 123 is an int not a double to make it a double change the file to be 123.0 and that should take care of it for you, the same for the other numbers in the file.
Also, when you post large sections of code please enclose them in the ubb code tags - see this page for more info on them.
Pip Vo
Greenhorn

Joined: Jul 18, 2001
Posts: 12
Dave:
Thanks. I changed my file to 123.0, 456.0, etc.
but still get wrong results (ERROR: NOT DOUBLE). This is driving me crazy.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It looks like the program has no problem converting "123" into a double - that isn't what it's complaining about. The problem is the ABC111 afterwards - you try to convert that to a double, and can't.
One hint is - when you get an exception, print out the exception itself (not just "ERROR: NOT A DOUBLE"). This will often have additional information which will better explain the problem for you. In this case, it will tell you what the text is which it can't convert to a double.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using doubleToString