Floating Point Literals
Floating point literals may be expressed in a variety of formats to simplify the task of expressing different ranges of values.
Rules
- Cannot start with 0 unless the 0 is followed by a decimal point.
- Can use 'e' notation to express exponential values (ke±n represents k·10±n).
- May include a decimal point (should be included when not using 'e' notation).
- Cannot include commas or spaces.
- Must use only the digits zero-nine.
- May be preceded by a minus sign "-".
Examples of Valid Floating Point Literals
2.56e-5 | 10.4378 | 48e8 | 0.5 | 10f | 10.2f |
The 'f' in the last two examples is a literal qualifier, described on the next page. It forces the compiler to treat it as a float, which would otherwise be treated as something else:
- 10 would be treated as an int
- 10.2 would be treated as a double
We'll see why this is important in the section on operators.
Examples of Invalid Floating Point Literals
0x5Ae-2 | 02.41 | F2.33 | 0x2.A |