Decimals in C++

This is a discussion on Decimals in C++ within the C++ Programming forums, part of the General Programming Boards category; How would I get 1960.00 - 666.40 = 1293.60 in a C++ program?? I don't want it to round the ...

  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 08:41 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    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, 03: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, 07:41 PM
  4. Accepting Decimals
    By dragon_man in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2003, 11:09 PM
  5. Decimals to Fractions
    By ToasterPas in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2001, 12:58 PM

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