Write Floating-Point Literals with an exponent : Float Point Data Type « Data Type « Java Tutorial






Write the number as a decimal value followed by an E, or an e.

  1. Floating-point literals are of type double by default.
  2. To specify a value of type float, you append an f, or an F.
public class MainClass{

  public static void main(String[] arg){
     double f1 = 1.496E8;
     double f2 = 9.0E-28; 
  
     System.out.println(f1);

     System.out.println(f2);
     System.out.println(f2 + f1);

  }

}
1.496E8
9.0E-28
1.496E8








2.10.Float Point Data Type
2.10.1.Floating-Point Data Types: memory and length
2.10.2.Write Floating-Point Literals with an exponent
2.10.3.Floating-Point Calculations
2.10.4.Using ++ and -- with floating-point variables
2.10.5.Applying the modulus operator, %, to floating-point values