I've made this code that, in theory (I'm pretty sure), should round any double to as many decimals as you want. However, some of the calculations are giving me some wierd numbers. Does anyone have any clue as to why?
The code's spacing got a little uneven for some reason.
public static void main(String[] args) {
double roundedNumber=76.9864590256; //Some test decimal I randomly punched in
for (double i = 0.0000000005; i<0.01; i*=10){
System.out.println("\n"+(roundedNumber+i)+"\n"+roundedNumber+((i*10)/5));
if (roundedNumber+i>=roundedNumber+((i*10)/5)){
roundedNumber=roundedNumber-(roundedNumber%(i*2))+((i*10)/5);
System.out.println("Round Up: "+roundedNumber);
}else{
roundedNumber=roundedNumber-(roundedNumber%(i*2));
System.out.println("Round Down: "+roundedNumber);
}
}
System.out.println("\n"+roundedNumber);
}

