Beginning Java Programming 4 Math Rounding and Types

114 Просмотры
Издатель
This video uses a class provided to my students to assist with rounding. For those following with out that, you need to add the following code to your program. Paste this outside your main method. When you see an example that uses "Round.roundToDecimals(...", you can now just type "roundToDecimals(...".

public static double roundToDecimals(double d, int c) {
long temp=(int)Math.round(d*Math.pow(10,c));
return (((double)temp)/Math.pow(10,c));
}
Категория
Язык программирования Java
Комментариев нет.