Answers for "int to float c++"

C++
2

cpp float to int

float a = 5.0;
int b = static_cast<int>(a);
Posted by: Guest on June-01-2021
1

double to float c++

double v1 = 20120313.0;
    float v2 = (float) v1;
Posted by: Guest on May-18-2020
2

int to float c++

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

how to make floats output with 2 decimals c++

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

int main()
{
	float x=10.3445f;
	
	cout<<fixed<<setprecision(5)<<x<<endl;
	cout<<fixed<<setprecision(2)<<x<<endl;
	cout<<fixed<<setprecision(3)<<x<<endl;
	cout<<fixed<<setprecision(0)<<x<<endl;
	
	return 0;
}
Posted by: Guest on April-18-2020
0

casting to a double in c++

double x;
x = (double) 25;
Posted by: Guest on July-06-2020

Browse Popular Code Answers by Language