C Programming Floating Point Literals

Last modified by Microchip on 2023/11/10 10:59

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 0-9
  • May be preceded by a minus sign "-"

Examples of Valid Floating Point Literals

2.56e-510.437848e80.510f10.2f

The f in the last two examples is a literal qualifier, described on the next page. It forces the compiler to treat as a float, what 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-202.41F2.330x2.A