printing large decimal numbers

This is a discussion on printing large decimal numbers within the C++ Programming forums, part of the General Programming Boards category; How do you print decimal numbers that are have more then 6 didgets? I'm writing a small prog to find ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    printing large decimal numbers

    How do you print decimal numbers that are have more then 6 didgets? I'm writing a small prog to find the square root of 50 but the decimals are large and it only prints out 6 spots. any idea what could remedy the situation? (Code is below)
    Code:
    #include <math>
    #include <iostream>
    
    double i = (double)sqrt(50.0) ;
    
    main (){
    cout << "square root of 50 :" << i ;
    }
    Last edited by Isometric; 03-20-2002 at 03:33 PM.
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You could try -

    Code:
    #include <cmath>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main (){
    	double i = sqrt(50.0) ;
    
    	cout << setprecision(10) << "square root of 50 :" << i ;
    
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    29
    #include <math.h>
    #include <iostream.h>
    #include<conio.h>
    float i = (float)sqrt(50.0) ;

    main (){
    cout << "square root of 50 :" << i ;
    getche();
    }
    This gives me a result of 7.07107
    Is that what you are looking for?
    -Colin

  4. #4
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Sorensen has the right idea. I would add the following:

    Code:
    #include <cmath>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main ()
    {
       double i = sqrt(50.0) ;
    
       cout << setprecision(10) << setiosflags(ios::fixed | ios::showpoint) << "square root of 50: " << i ;
    
       return 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Originally posted by biosx

    Code:
       cout << setprecision(10) << setiosflags(ios::fixed | ios::showpoint) << "square root of 50: " << i ;
    }
    Please explain this line? what is setprecision and setiosflags?

    Also Colin that is what I'm getting now but there is really alot or didgets. That squared is 50.0000309449. The real number will be 5 squareroots of 2 but I want a decimal number for it.
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  6. #6
    Unregistered
    Guest
    Download a package called NTL. It is a C++ package that allows abitrary precision math. You can find it through any search engine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Large numbers
    By password in forum C++ Programming
    Replies: 9
    Last Post: 06-28-2007, 02:15 AM
  2. Modulo on decimal numbers
    By (Slith++) in forum C++ Programming
    Replies: 3
    Last Post: 12-17-2005, 02:29 AM
  3. Printing numbers in hex format
    By miclus in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2005, 06:04 AM
  4. Large Numbers
    By Hypercase in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2004, 06:56 PM
  5. Help me for repeating decimal numbers plz
    By Supra in forum C Programming
    Replies: 3
    Last Post: 09-27-2001, 03:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21