Java float type
In this chapter you will learn:
- What is Java float type
- Value and size for Java float type
- How to create float literals
- Example - Java float literal
float type
float
type represents single-precision numbers.
float
type variables are useful when you need a fractional component.
Here are some example float variable declarations:
float high, low;
Value and size
float is 32-bit width and its range is from 1.4e-045
to 3.4e+038
approximately.
Literals
Floating-point literals in Java default to double precision.
To specify a float literal, you must append an F
or f
to the constant.
Example 1
The following code shows how to declare float literals.
public class Main {
public static void main(String args[]) {
float d = 3.14159F;
System.out.print(d);//3.14159
} //ww w. j av a 2 s.c o m
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- What is Java double type
- Size and value for Java double type
- Example - Java double type
- How to create double type Literals
- Literal Letter
- Scientific notation
- double value constant
- How to get the value of double infinity
- What is double type NaN(Not a Number)