I work with the cos value, which is represented in double. Thus, my borders are between -1.0 and 1.0, however for my work I just ignore all negative variables.
Now I would like to get the decimal number of this double number (sorry I could not find the literary term for this operation)
Mostly with examples:
Suppose the input is 0.12, then it can be written as 1.2 * 10 ^ -1, what I expect to get is just the part where it is 10 ^ -1
Another example is 0.00351, which can be written as 3.51 * 10 ^ -3, so the expected result is 10 ^ -3
I developed this algorithm below, but it’s kind of fast and dirty. I was wondering if there was any math trick to avoid using a loop.
double result = 1;
while (input < 1.0) {
input *= 10.0;
result /= 10.0;
}
, 0.
Java , .