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

- 01-30-2010, 05:58 PMfataguilaStore the decimal number into an variable
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.

- 01-30-2010, 06:11 PMtravishein
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

- 02-01-2010, 01:19 AMfataguila
Thanks it worked out although I think i'm just gonna make the double variable into an integer and it gets truncated:

- 02-01-2010, 02:41 AMcollin389Quote:

Thanks it worked out although I think i'm just gonna make the double variable into an integer and it gets truncated:

Code:`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. - 02-01-2010, 07:22 PMfataguila
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