Answers for "set precision in floating points in c++"

C++
1

set precision in c++

#include <iomanip.h>
#include <iomanip>
int main()
{
    double num1 = 3.12345678;
    cout << fixed << showpoint;
    cout << setprecision(2);
    cout << num1 << endl;
}
Posted by: Guest on September-16-2021
2

how to print 5 precision float in c++

#include <iostream>
#include <cstdio>
using namespace std;

int main() 
{
    // This code helps you to print a number with desired decimal
    double Number=10.3454;
    printf("%.3lf",Number);

    return 0;
}
Posted by: Guest on June-07-2020
1

set precision in c++

#include <iostream>

int main()
{
  std::cout << std::setprecision(n); //to n SIG FIG
  // any cout comand will be to n sig fig after this comand
}
Posted by: Guest on January-17-2022
0

set precision on floating numbers

#include <iostream>
#include <iomanip>
#include <vector>

using std::cout; using std::endl;
using std::vector; using std::fixed;
using std::setprecision;

int main() {
    vector<double> d_vec = {123.231, 2.2343, 0.012,
                            26.9491092019, 113, 0.000000234};

    for (auto &i : d_vec) {
        cout << i << " | ";
    }
    cout << endl;

    for (auto &i : d_vec) {
        cout << setprecision(3) << i << " | ";
    }
    cout << endl;

    return EXIT_SUCCESS;
}
Posted by: Guest on March-03-2022

Code answers related to "set precision in floating points in c++"

Browse Popular Code Answers by Language