Round vector values

    0

    0

    Giovanny Gongora

    Codiga's C++ Recipes

    Take each vector float and round it

    #include <iostream>
    #include <vector>
    #include <cmath>
    
    std::vector<double> myvec = {2.3, 5.5, 7.8, -2.3, -5.5, -7.8};
    for(double d : myvec){
      std::cout << d << "->" << round(d) << std::endl;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.