Skip to main content

2.2) Primitive Data Types of C++: Floating-Point Values


Available types:

  • float (occupies 4 bytes, accurate to ~7 digits)
  • double (occupies 8 bytes, accurate to ~15 digits)
  • long double (occupies 12 or 16 bytes, accurate to ~18 digits)

(Note: floating-point values are represented internally using two components: an exponent and a significand. The numbers of digits of accuracy quoted here are for the significand rather than the entire number)

Representation of literal values:

  • Values are distinguished from integers by use of a decimal point - e.g., 41.99
  • Values can be expressed in scientific notation - e.g., 5.67e-3 is 5.67 X 10-3
  • To indicate a literal float value, use F or f as a suffix - e.g., 41.99F
  • To indicate a literal long double, use L as a suffix - e.g., 41.99L (as with long integers the lowercase L suffix is best avoided)