Displaying floats properly.

I'm having issues displaying the full number of a float.

Example:
#include <iostream>
using namespace std;

float apple = 1.50f;
int main()
{
cout << float(apple) << endl;
// Outputs: '1.5', instead of: '1.50'.
return 0;
}

Is there a way I can solve this issue ?
Last edited on
If you always want to show two digits after the decimal dot you can include <iomanip> and use std::fixed and std::setprecision(2).

1
2
3
4
std::cout << std::fixed << std::setprecision(2);

float apple = 1.5f;
std::cout << apple; // outputs 1.50 
It works!
Thanks, heaps bro.
Topic archived. No new replies allowed.