How can I store the decimal point of a number into a variable. Let's say I have 32.6 is there anyway to store the .6 into a variable or an array. Thanks any help would be greatly appreciated.
Printable View
How can I store the decimal point of a number into a variable. Let's say I have 32.6 is there anyway to store the .6 into a variable or an array. Thanks any help would be greatly appreciated.
I would try to use the Math.truncate facility, to obtain the whole number part of the original number, and then subtract that from it, the remaining part will be the decimal place
Thanks it worked out although I think i'm just gonna make the double variable into an integer and it gets truncated:
This is not a very good idea. If you say:Quote:
Thanks it worked out although I think i'm just gonna make the double variable into an integer and it gets truncated:
c = 0.6000000000000014Code:double a = 32.6;
int b = (int)a;
double c = a-b;
As you can see this would most likely mess up some stuff in your code.
Well not really just did it
Code:
int Num1;
String lengthString = Integer.valueOf(Num1).toString();
int Vec[]=new int[lengthString.length()];
double x1=Num1;
double x2;
int c=lengthString.length();
for (int a=0; a<lengthString.length(); a++)
{
x2=x1/10;
x2=(int)x2*10;
c--;
Vec[c]=(int)x1-(int)x2;
x1=x2/10;
}
Vec[]=Num1