Floating-Point Literals in Java Programming
Previous | Home | Next |
Floating-point numbers are like real numbers in mathematics,
for example, 6.12536, -0.00002331
A floating-point literal can be denoted as a decimal point, a fraction part,
and as an integer. We also add a suffix to the floating point literal as D, d, F or f.
The type of a floating-point literal defaults to double-precision floating-point.
The following floating-point literals represent double-precision floating-point and floating-point values.
declaration of floating literals are:
2.0f
2.01d
.3f
double d1 = 4.0;
double d2 = 2.14159;
double d3 = 0.7666;
public class Main {
public static void main(String[] argv) {
double d1 = 4.0;
double d2 = 2.14159;
double d3 = 0.7666;
System.out.println("d1 is " + d1);
System.out.println("d2 is " + d2);
System.out.println("d3 is " + d3);
}
Previous | Home | Next |