Elementary question

This is a discussion on Elementary question within the C++ Programming forums, part of the General Programming Boards category; Hi everyone. I have a simple question that i don't knot it : I have the next division : 296/91=3,2527472527472527472527472527473 ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    5

    Elementary question

    Hi everyone. I have a simple question that i don't knot it :

    I have the next division :

    296/91=3,2527472527472527472527472527473

    I want print the result of it, but only with 4 decimals. What is the command ?

    Thank you!

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Look up the stream manipulators in the iomanip header such as setprecision.

    [edit]Code sample follows:[/edit]

    Code:
    #include <iostream>
    #include <iomanip>
    
    int main()
    {
        double p = 12.345467889;
    
        std::cout << p << std::endl;
        std::cout << std::setprecision(8) << p << std::endl;
    
        return 0;
    }
    Attached Images Attached Images  
    Last edited by hk_mp5kpdw; 03-02-2011 at 01:53 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question bout my work
    By SirTalksAlots in forum C Programming
    Replies: 4
    Last Post: 07-18-2010, 04:23 PM
  2. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 06:24 AM
  3. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 05:52 PM
  4. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM

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