Menu
Topics Index
...
`


Datatypes > Primtive Dataypes > Literals >
Siva Nookala - 11 Apr 2016
Floating Point Literals In Java contains the fractional parts. e.g., 251.73, 3.14, 98766.12, 10E+03, 2.78e-7. If the Floating Point Literal is suffixed with letter F or f, then it is of type float. So 251.73 is of type double where as 251.73f is of type float.

Floating Point Literals include float and double Data types. The default data type of Floating Point Literals is double, but you can designate it explicitly by appending the D (or d) suffix. However, the suffix F (or f) is appended to designate the data type of a Floating Point Literal as float. We can also specify a Floating Point Literal in scientific notation using exponent (E or e). Below are few samples on how to convert from the exponential format to decimal format.

0.0314E2 = 0.0314 * 10^2 = 0.0314 * 100 = 3.14
4E+7 = 4 * 10^7 = 4 * 10000000 = 40000000
5.25e-6 = 5.25 / 10^6 = 5.25 / 1000000 = 0.00000525
double d1 = 123.4; // represents d1 as double value
double d2 = 1.234e2; // same value as d1, but in scientific notation
double d3 = 123400E-3; // same value as d1, but using negative exponential
float f1  = 123.4f; // represents f1 as float value
float f2  = 12.34E+01f; // same value as f1, but in scientific notation

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App