Jump to content
  • Advertisement
Sign in to follow this  
jordi_0071

variable wich on?

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey i write this code: #include <iostream> using namespace std; int main() { float sum; int ten = 10; float pi = 3.10; sum = pi + ten; cout << "The sum as whole number: " << sum << endl; return 0; } the anwnser is 13.10 but it shows 13.1! how do i show 13.10?

Share this post


Link to post
Share on other sites
Advertisement
Formatted output using the functions of C would work.

#include <stdio.h>

int main()
{
float number = 3.45;

printf( "%.5f and %f", number, number );

return 0;
}

// Output: 3.45000 and 3.45

Share this post


Link to post
Share on other sites
Or, the C++ way using cout: (EDIT: just realised, moeron actually pointed it out)

#include <iostream>
#include <iomanip> //Used for setprecision

int main()
{
const float myFloat = 13.1f;
std::cout << std::fixed << std::setprecision(2) << myFloat << std::endl;

return 0;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!