Jump to content

should be easy, but please look

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
romanbodenmiller

romanbodenmiller

    Newbie

  • Members
  • Pip
  • 6 posts
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";
}

#2
romanbodenmiller

romanbodenmiller

    Newbie

  • Members
  • Pip
  • 6 posts
nevermind i found this:
cout << "num = " << setprecision(2) << num;

#3
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
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++.