Defining Floating-Point Variables - C++ Data Type

C++ examples for Data Type:float

Introduction

Floating-Point Data Types

Data Type Description
float Single precision floating-point values
double Double precision floating-point values
long double Double-extended precision floating-point values

Floating-Point Type Ranges

Type Precision (Decimal Digits) Range
float 71.2x10^-38 to 3.4x10^38
double 15 2.2x10^-308 to 1.8x10^308
long double19 3.3x10^-4932 to 1.2x10^4932

Here are some statements that define floating point variables:

Demo Code

#include <iostream>

int main()/*ww  w . j  av a 2  s . co m*/
{
    float inches_to_mm {25.4f};
    double pi {3.1415926};                         // Ratio of circle circumference to diameter
    long double root2 {1.4142135623730950488L};    // Square root of 2

    std::cout << "inches_to_mm:" << inches_to_mm << std::endl;
    std::cout << "pi: " << pi << std::endl;
    std::cout << "root2: " << root2 << std::endl;
}

Result


Related Tutorials