So, following on from previous post about beginners guides to making apps, I’ve decided to learn a little java.
I’ve got my program working, only I’m stuck on one last part.
I’ve got an array of float values called weights[]
I can print these by saying:
System.out.println("Weight 1:" + weights[0]);
System.out.println("Weight 2: " + weights[1]);
System.out.println("Weight 3: " + weights[2]);
System.out.println("Weight 4: " + weights[3]);
Oh, I also know that I could do this with a loop, but it’ll change a little in future and the text descriptions will be different so I won’t be able to use a loop.
I want to be able to print these but only to 2 decimal places.
I thought I’d be able to use:
System.out.println("Weight 1: %.2f", weights[0]);
But it gives an error.
I’m happy to round the values within the array to 2DP first, but I’m not sure how to do that either and would rather preserve the full value and just round it at the output.
Any help would be great!