C++ float type Variables

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 (+or)
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:

#include <iostream>

int main()/*from   ww  w  . ja  va 2s .  c  om*/
{
    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;
}



PreviousNext

Related