Answers for "convert to float c++"

C++
3

how to change a string to an float in c++

#include <iostream>
#include <string>

int main() {
    std::string str = "123.4567";

    // convert string to float
    float num_float = std::stof(str);

    // convert string to double
    double num_double = std::stod(str);

   std:: cout<< "num_float = " << num_float << std::endl;
   std:: cout<< "num_double = " << num_double << std::endl;

    return 0;
}
Posted by: Guest on August-27-2020
2

int to float c++

int a = 3;
float b = (float)a;
Posted by: Guest on February-28-2020
1

c++ std string to float

std::string num = "0.6";
double temp = ::atof(num.c_str());

std::cout << temp << std::endl;
// Output: 0.6
Posted by: Guest on February-27-2021

Browse Popular Code Answers by Language