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.
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("\\."));