I tried the following code :
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int intvar = 25;
float floatvar = 35.87;
cout << "intvar= " << intvar;
cout << "\n floatvar =" << floatvar;
cout << "\n float(intvar)=" << float(intvar);
cout << "\n int(floatvar)=" << int(floatvar);
_getch();
return 0;
}
The result for float(intvar)
is coming as 25
.
Can someone please explain why it is still being shown as an integer and not 25.000000
?
You need to specify the format for floatingPoint output, such as:
From [The.C++.Programming.Language.Special.Edition] 21.4.3 FloatingPoint Output [io.out.float]: