package class2_2_OfficeHours_start;// Dr. Yoder. MSOE. 15 March 2017 import com.sun.org.apache.bcel.internal.generic.FLOAD; public class AssigningDoubleToFloat { /** This program is to answer the question: * Why do we write the f after the 1.0 in 1.0f * (e.g. in the first line of program below * or on the practice half exam 1)? * Why not simply write float f = 1.0? Isn't 1.0 * a number with a decimal part anyway? * * The key to this question is that the float type * uses only 32 bits and the double type uses 64 bits. * So the float can only store about seven digits after * the decimal point while the double can store about 16. * * In this example, even though I put 11 digits of PI * in the floating-point constant, only about seven * are actually stored as you can see when I copy * them back into the double. * * The real value of pi continues ...265359 * but our value from the float continues ...274101 * So there really aren't any correct digits after * that last 26 (or 27 if you round). * @param args ignored. */ public static void main(String[] args) { float f = 1.0f; float pi = 3.14159265359f; System.out.println(" pi = " + pi); System.out.println(" (double) pi = " + (double) pi); System.out.println("3.14159265359 = " + 3.14159265359); } }