im having trouble where my dev c++ doesnt output to screen all the digits in this number 78.374625 its only posting 78.374 to the screen.What am i doing wrong?
i would put code tags but i dont know how
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
// float interest=8.675;
float number=78.374625;
int a;
cout <<number;
for (a=0;a <3; a++)
{
cout<<"\n";
cout <<" ";
cout <<a ;
cout<<"\n";
}
should be easy, but please look
Started by romanbodenmiller, Dec 11 2008 04:12 PM
2 replies to this topic
#1
Posted 11 December 2008 - 04:12 PM
|
|
|
#2
Posted 11 December 2008 - 05:29 PM
nevermind i found this:
cout << "num = " << setprecision(2) << num;
cout << "num = " << setprecision(2) << num;
#3
Posted 11 December 2008 - 06:46 PM
Basically,both float and double has limited precision. changing float to double may solve your problem because double can have around 15 significant digits.
float and double are meant for scientific calculation, if you want numbers be maintained exactly as its decimal format, you may need to write you own fixed point number class or use a third party class. There is no built-in fixed point type in C/C++.
float and double are meant for scientific calculation, if you want numbers be maintained exactly as its decimal format, you may need to write you own fixed point number class or use a third party class. There is no built-in fixed point type in C/C++.


Sign In
Create Account

Back to top









