# Help in two decimal places

hi i'm new in c++
and i need some help to output 2 decimal places in float.
example:
if the output is 9.9(float) i want to be 9.90(float)
or 35(float) i want to be 35.00(float)
and so on.

• : hi i'm new in c++
: and i need some help to output 2 decimal places in float.
: example:
: if the output is 9.9(float) i want to be 9.90(float)
: or 35(float) i want to be 35.00(float)
: and so on.
:
:
[code]
#include
#include

int main()
{
float f = 9.0;
printf("%.2f
",f);
system("pause");
return 0;
}
[/code]

• : : hi i'm new in c++
: : and i need some help to output 2 decimal places in float.
: : example:
: : if the output is 9.9(float) i want to be 9.90(float)
: : or 35(float) i want to be 35.00(float)
: : and so on.

And now the way you're solving problems like that in C++:
[code]
#include
#include //that's the header file you need in this
case!
using namespace std;

int
main (void)
{
float f = 9.9;

cout << setprecision (2) << f << endl;

return 0;
}
[/code]

Now let's just say something about the source code you might understand but which functions you don't know!

`setprecision ()' is a so called IO-Manipulator (therefor he stands in the iomanip!)

You might want to take a look at a reference of the c++ standard library! For example: http://www.cplusplus.com/ref/iostream/iomanip/index.html

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!