# Thread: Store the decimal number into an variable

1. Member
Join Date
Jan 2010
Posts
4
Rep Power
0

## 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.

2. 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

3. Member
Join Date
Jan 2010
Posts
4
Rep Power
0
Thanks it worked out although I think i'm just gonna make the double variable into an integer and it gets truncated:

4. Senior Member
Join Date
Nov 2009
Posts
235
Rep Power
8
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:
Java 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.

5. Member
Join Date
Jan 2010
Posts
4
Rep Power
0
Well not really just did it
Java 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```
Last edited by Fubarable; 02-01-2010 at 08:31 PM. Reason: code tags added

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•