Floating Point Literal : Primitive Data Type in Java Programming

Floating Point Literal : Primitive Data Type in Java Programming

  1. Decimal values with a fractional component is called floating point.
  2. They can be expressed in either standard or scientific notation.

[468x60]

Standard Notation

  1. Standard notation consists of a whole number component followed by a decimal point followed by a fractional component.
  2. For example : 78.0, 3.14159 represent valid standard-notation floating-point numbers.

Scientific Notation

  1. Scientific notation uses a standard-notation, floating-point number plus a suffix that specifies a power of 10 by which the number is to be multiplied.
  2. The exponent is indicated by an E or e followed by a decimal number, which can be positive or negative.
  3. Valid Examples are :
    • 6.02E21
    • 314159E–05
    • 2e+100.
  4. Floating-point literals in Java default to double precision.
[468x60]
Literal Representation Size Default

Floating Point Number

F or f

32 bits

-

Double Number

D or d

64 bits

It is default type

Live Example : Assigning Values to Floating Point Literal

public static void main(String args[])
{
double d1 = 45.6;
float  f1 = 32.5;
}

Short Notes :

  1. Jdk 7 also provides us facility for writing hexadecimal literal but they are rarely used.
  2. We can use Underscore inside Literals.
double num = 1_567_2_82.0;

Literals in Java : Integer | Float | Character | Boolean