Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ float and double Different Precisions For Different Variables

#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    // Creating a double type variable
    double a = 3.912348239293;

    // Creating a float type variable
    float b = 3.912348239293f;

    // Setting precision to 11 for double
    cout << "Double Type Number = " << setprecision(11) << a << endl;

    // Setting precision to 7 for float
    cout << "Float Type Number  = " << setprecision(7) << b << endl;

    return 0;
}
Comment

C++ float and double Using setprecision() For Floating-Point Numbers

#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    // Creating a double type variable
    double a = 3.912348239293;

    // Creating a float type variable
    float b = 3.912348239293f;

    // Setting the precision to 12 decimal places
    cout << setprecision(13);

    // Printing the two variables
    cout << "Double Type Number  = " << a << endl;
    cout << "Float Type Number      = " << b << endl;

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: shift element to end of vector c++ 
Cpp :: c++ program to find gcd of 3 numbers 
Cpp :: sum of n natural numbers 
Cpp :: c++ linked list 
Cpp :: how to make a pointer point to a the last value in an array 
Cpp :: convert single character string to char c++ 
Cpp :: C++ Taking Multiple Inputs 
Cpp :: how to rotate a matrix 90 degrees clockwise 
Cpp :: tr bash 
Cpp :: cpp substring 
Cpp :: How to see gateway on linux 
Cpp :: binary tree 
Cpp :: floyd algorithm 
Cpp :: cout in c++ 
Cpp :: cpprestsdk send file 
Cpp :: Consell de forces polítiques de Catalunya 
Cpp :: building native binary with il2cpp unity 
Cpp :: C++ Volume of a Cube 
Cpp :: how to find second smallest element in an array using single loop 
Cpp :: Minimizing the dot product codechef in c++ 
Cpp :: cap phat dong mang 2 chieu trong c++ 
Cpp :: input time from console C++ 
Cpp :: check .h files syntax c++ 
Cpp :: grepper users assemble 
Cpp :: and condtion c++ 
Cpp :: lru cache gfg 
Cpp :: c++ vector add scalar 
Cpp :: distinct numbers cses 
Cpp :: how to extract a bit from a byte in c++ 
Cpp :: c++ constructor initializing list 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =