Hi, I'm trying to set a double-value, but somehow it does not take my statements. This is what I got:

public double getDouble()
{
return aDoubleValue;
}

public double getAnothertDouble()
{
return aDoubleValue2;
}

public void myMethod(MagicObject a)

/*
Some magic
*/

//Here lies the problem: (FX is a doublevalue, and by it self FX/a.getAnotherDouble() gives this value: 1.541900433861831E-6, when printed. a.getDouble = 0 when printed
double ad = (double)(a.getDouble()+(FX/a.getAnotherDouble()));

}

So.. when i try to set what "ad" is I always get the value of a.getDouble(), and not the value of what i want.

Any help?

Edit:
Ohh, yeah, i got a set method for those too.

Edited 6 Years Ago by Cort3z: n/a

1.541900433861831E-6 is an extremely small value. Perhaps you are experiencing a precision problem due to how small it is, it can only register as 0 in a double?

A second possibility is that println() is not printing your value to enough decimal places in order for you to see anything but the 0's.

Edited 6 Years Ago by BestJewSinceJC: n/a

No. It prints just fine, and it is well within the precision of a double. There is simply something that prohibits me from adding the doubles together. I get the value i want if I enter the expression into my outprint, but when I say:

double ad = (a.getDouble()+(FX/a.getAnotherDouble()));

system.out.println("ad = " +ad); //prints "0.0"

system.out.println("expression = "+(FX/a.getAnotherDouble())); //Prints  "1.541900433861831E-6"

Here my a.getDouble() is returning 0.0. If i change my variable in a to return 1.0 the total expression becomes 1.0 (a.getDouble+FX....).

When i only have my FX expression all goes well.

Very strange indeed.

I'm sure there is a good explanation, but I've tested that on my machine and I always get the expected output. Could it be something to do with your 'a' class (whatever that is)? For example, print out both FX and in the method that returns the doubles, from within that method, print out the value.

Edited 6 Years Ago by BestJewSinceJC: n/a

OMG! I found the error now! Thanks for the help. The problem was a logical error in my run method that made the "magic" part run twice, and then it canceled itself out! LOL! I basicly added it all the way it should have, but then subtracted that exact same number again. :p

Stupid of me. But thanks anyway!

This article has been dead for over six months. Start a new discussion instead.