# how to only get the decimal of a number

the assignment that I am working on requires that you take the floating point of a number. For example, if I had 4.233, it would only give me (.233). How would I be able to do this? I tried to use the % operator; however, it does not give the exact results.

Thank You

Split on "." and then pop the first element out

Possible duplicate of How do I get whole and fractional parts from double in JSP/Java?

### 3 Answers

There are basically two ways. Numerically, you can subtract the `int`

value of the initial `double`

value to get the part that is floating point. Or, you can convert to a `String`

and split on the decimal point. Like,

```
double d = 4.233;
double fp = d - (int)d;
System.out.printf("%f%n", fp);
System.out.printf(".%s%n", String.valueOf(d).split("\\.")[1]);
```

I get

```
0.233000
.233
```

respectively.

Thanks Everyone. I relize my mistake; and quite frankly its pretty funny haha. I hope this lightened someone's day; and yes, this was a real question that got me for over an hour :[

Please provide a Minimal, Complete, Verifiable example.