# Store the decimal number into an variable

• 01-30-2010, 06:58 PM
fataguila
Store 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, 07:11 PM
travishein
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, 02:19 AM
fataguila
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, 03:41 AM
collin389
Quote:

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:
Code:

```double a = 32.6; int b = (int)a; double c = a-b;```
c = 0.6000000000000014

As you can see this would most likely mess up some stuff in your code.
• 02-01-2010, 08:22 PM
fataguila
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```