Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #set #precision #floating #numbers
ADD COMMENT
Topic
Name
3+3 =