Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to get 4 decimal places in c++

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    double d = 122.345;
    cout << fixed << setprecision(4) << d;
}
Comment

how to specify the number of decimal places in c++

#include<bits/stdc++.h>
using namespace std;
int main ()
{
    double A, n, R, Square_of_R;
    cin >> R;
    Square_of_R = pow(R,2);
    n = 3.14159;
    A = n * Square_of_R;
    cout << "A=" << fixed << setprecision(4) << A << endl; 
  	//printf("A=%.4lf", A);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ find key in hashmap 
Cpp :: vector of structs c++ 
Cpp :: C++ shortcuts in desktopp app 
Cpp :: number to binary string c++ 
Cpp :: prime number program in c c++ 
Cpp :: use c++17 g++ 
Cpp :: how to make a 2d vector in c++ 
Cpp :: c++ split string by space into vector 
Cpp :: binary exponentiation modulo m 
Cpp :: resize two dimensional vector c++ 
Cpp :: c++ check if string contains non alphanumeric 
Cpp :: how to print fixed places after decimal point in c++ 
Cpp :: insertion sort c++ 
Cpp :: convert string into integer in c++ 
Cpp :: to_string c++ 
Cpp :: minimum spanning trees c++ 
Cpp :: what is the short cut way to find the max and min element in an array in c++ 
Cpp :: how to do (binary) operator overloading in c++ 
Cpp :: input 2d vector c++ 
Cpp :: c++ char to uppercase 
Cpp :: how to use decrement operator in c++ 
Cpp :: string vector c++ 
Cpp :: insert vector to end of vector c++ 
Cpp :: flags for g++ compiler 
Cpp :: C++ string initialization 
Cpp :: string to decimal c++ strtol 
Cpp :: c++ for else 
Cpp :: vector reverse function in c++ 
Cpp :: continue c++ 
Cpp :: c++ string to char array 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =