0

Okay, so here's how this has been going:

I want to take a double value in side an array (e.g. arr[0] = 3.42) I want to only display the decimal value of this array. When I try to do the following:

arr[0] -= 3;

It will assign the value .4199999999993 to arr[0]... I just need the value .42. I was told there are other ways of pulling only the decimal portion of a double value, but I'm not familiar with said methods.

1 Answers1

0

How about something like this:

public static void main(String[] args) {
    double[] arr = {3.42};
    arr[0] -= 3.0;
    double tenTimes = Math.ceil(arr[0] * 100);
    double result = tenTimes/100;

    System.out.print(result);
}
Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45