I want to format a Double obtained from an Object so it only displays three digits after the decimal point. Here's the current code: 
 Three a = Data.get(index); 
 // Get the y-axis acceleration value
 double b = a.getY();
 String accelerationOutUnfiltered = Double.toString(b);
 Data[0] = accelerationOutUnfiltered;
Note: I am doing this in Android, and when I use String.format("%.3f", y) this doesn't work and it throws me a error in Android Studio. Currently the above code works but it displays 15 digits after the decimal point. 
I have tried several forms, but they all have failed. Please help. Thanks :)
 
     
    