Floating Point Literal : Primitive Data Type in Java Programming
Floating Point Literal : Primitive Data Type in Java Programming
- Decimal values with a fractional component is called floating point.
- They can be expressed in either standard or scientific notation.
Standard Notation
- Standard notation consists of a whole number component followed by a decimal point followed by a fractional component.
- For example : 78.0, 3.14159 represent valid standard-notation floating-point numbers.
Scientific Notation
- 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.
- The exponent is indicated by an E or e followed by a decimal number, which can be positive or negative.
- Valid Examples are :
- 6.02E21
- 314159E–05
- 2e+100.
- Floating-point literals in Java default to double precision.
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 :
- Jdk 7 also provides us facility for writing hexadecimal literal but they are rarely used.
- We can use Underscore inside Literals.
double num = 1_567_2_82.0;
Literals in Java : Integer | Float | Character | Boolean