|
-
Oct 21st, 2004, 06:33 AM
#1
Int to Double....
This is starting to irritate me. I have done to much C++ lately, so I am totaly off simple things in Java, and I have to do this assignment in Java...
Well I have a 2d array of INTs, and I want to convert one and one of them to a double. How do I do that?
I am extending a hoppfield class my teacher have made, and in his kode he has even written:
double d = 0.0D;
and it works...then 2 lines under that I wrote:
double d = 0.0D;
for(int k = 0; k < inn.length; k++)
double fix = 0.0D;
and I am getting an error on the "fix" variable, saying a .class is expected. How can I not get an error on his line but on my line? I hate it when Java is that little concise(SP?).
Well back to the topic. I thought there was a toDouble function, but I can only find one for Booleans, and I don't have my books with me. Any help?
Last edited by NoteMe; Oct 21st, 2004 at 04:22 PM.
-
Oct 21st, 2004, 07:27 AM
#2
I suggest putting braces around the for-block, that could be the source of the error.
Btw, I think that's consistent with C++'s behaviour 
For converting a single int to double, you can just assign it, the conversion ought to be done implicitely. If not, you can cast it explicitely:
double d = (double)i;
or use the Integer class:
double d = new Integer(i).doubleVal();
(yuck!)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 21st, 2004, 04:21 PM
#3
Originally posted by CornedBee
I suggest putting braces around the for-block, that could be the source of the error.
Btw, I think that's consistent with C++'s behaviour 
For converting a single int to double, you can just assign it, the conversion ought to be done implicitely. If not, you can cast it explicitely:
double d = (double)i;
or use the Integer class:
double d = new Integer(i).doubleVal();
(yuck!)
I tried the first method there. With (double). But I got the same error. The thing is that I revers engineered the java package my teacher had made, to edit his code so it could be used for this assignment. So the for block was all ready there. Right before I left for work I saw he had skipped the { } after the for statement, and managed to pull it of with the (double), just didn't have the time post a reply. But thanks for the other method to. I hate that it has to be so complicated to cast datatypes. "Integer(i).doubleVal();" this should not be nessesary to do. Well, at least it is an other way to do it. Thanks for the reply. See you around.
ØØ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|