C++ float type Literals

Introduction

The float literals have f (or F) suffix and long double literals have L (or l) suffix.

Floating point literals without a suffix are of type double.

A floating-point literal can be either a decimal point, or an exponent, or both.

Here are some floating-point literals that include an exponent:

5E3 (5000.0)   100.5E2 (10050.0)   2.5e-3 (0.0025)   -0.1E-3L (-0.0001L)   .345e1F (3.45F)
#include <iostream>

int main()/*w  w  w. j  a  v  a2  s .co  m*/
{
    float f {5E3};

    std::cout << "f:" << f << std::endl;
}



PreviousNext

Related