Floating-Point Literals - C++ Data Type

C++ examples for Data Type:float

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)

Demo Code

#include <iostream>

int main()//ww  w  . ja v a 2s  .  c  o m
{
    float f {5E3};

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

Result


Related Tutorials