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 :: how to calculate bitwise xor c++ 
Cpp :: c preprocessor operations 
Cpp :: c define 
Cpp :: factorial calculator c++ 
Cpp :: stack implementation through linked list 
Cpp :: intersection.cpp 
Cpp :: opengl draw semi circle c++ 
Cpp :: c++ hash combine 
Cpp :: c++ program to convert kelvin to fahrenheit 
Cpp :: login system with c++ 
Cpp :: quicksort 
Cpp :: all permutations with repetition C++ 
Cpp :: cin exceptions c++ 
Cpp :: c++ exceptions 
Cpp :: vector iterating in c++ 
Cpp :: How to turn an integer variable into a char c++ 
Cpp :: c++ how to return an empty vector 
Cpp :: char to int in c++ 
Cpp :: iostream c++ 
Cpp :: c++ forbids comparison between pointer and integer 
Cpp :: c++ uint8_t header 
Cpp :: text color c++ 
Cpp :: C++ program to sizes of data types 
Cpp :: c++ map lookup 
Cpp :: c++ formatting 
Cpp :: c++ call by value 
Cpp :: cyclically rotate an array by once 
Cpp :: how can I delete a substring from a string in c++? 
Cpp :: C++ vector structure 
Cpp :: cpp custom exception 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =