Floating point literals may be expressed in a variety of formats to simplify the task of expressing different ranges of values.
- 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
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