public class Floating { public static void main(String[] args) { float f = 3.141592653f; //f avoids warning double d = 3.14159265358979323846; //will hold more digits System.out.println(f); System.out.println(d); System.out.println(10.0 / 3.0); System.out.println(10.0 / 0.0); //infinity System.out.println(-10.0 / 0.0); //negative infinity System.out.println("float: " + Float.MIN_VALUE + " to " + Float.MAX_VALUE); System.out.println("double: " + Double.MIN_VALUE + " to " + Double.MAX_VALUE); //Round to nearest int; if tied, rounds up (towards positive infinity). System.out.println(Math.round(2.5)); //prints 3 System.out.println(Math.round(-2.5)); //prints -2 //Towards negative infinity. System.out.println(Math.floor(2.5)); //prints 2.0 System.out.println(Math.floor(-2.5)); //prints -3.0 //Cast rounds towards zero. System.out.println((int)2.5); //prints 2 System.out.println((int)-2.5); //prints -2 System.exit(0); } }