Thread: Decimals in C++

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    24

    Decimals in C++

    How would I get 1960.00 - 666.40 = 1293.60 in a C++ program?? I don't want it to round the numbers. I tried:

    cout << fixed << showpoint << setprecision (2);

    but it did not work.
    Last edited by slimdime; 09-02-2010 at 07:41 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    std::cout << 1960.0 - 666.4 << std::endl;
    Should work.

    Code?
    (Beware of inaccuracies.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    24

    Thumbs up

    That worked!! Thanks Elysia.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with Decimals
    By ls1211 in forum C++ Programming
    Replies: 10
    Last Post: 09-11-2009, 02:04 PM
  2. Need help to show decimals
    By engstudent363 in forum C Programming
    Replies: 4
    Last Post: 02-19-2008, 04:13 PM
  3. allow decimals
    By dankassdann in forum C++ Programming
    Replies: 3
    Last Post: 10-28-2006, 06:41 PM
  4. Accepting Decimals
    By dragon_man in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2003, 10:09 PM
  5. Decimals to Fractions
    By ToasterPas in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2001, 12:58 PM