Results 1 to 3 of 3

Thread: cout<<5/2 outputs a integer?

  1. #1
    Join Date
    Jul 2010
    Posts
    34
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default cout<<5/2 outputs a integer?

    Hi,

    When I try to execute the following, I get an int when it should have been a float.

    Qt Code:
    1. std::cout<<5/2;
    To copy to clipboard, switch view to plain text mode 

    I get the output 2 and not 2.5 . How do I make it output 2.5?

    regards

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: cout<<5/2 outputs a integer?

    This is a very fundamental question and not related to Qt.

    You might want to google "C++ division"

  3. #3
    Join Date
    Jul 2010
    Posts
    34
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cout<<5/2 outputs a integer?

    Ok, got it !! Thanks.

Similar Threads

  1. Qt Creator where is cout in Qt Creator
    By hqking1988 in forum Qt Tools
    Replies: 8
    Last Post: 12th September 2019, 22:32
  2. where is cout
    By hqking1988 in forum General Programming
    Replies: 3
    Last Post: 22nd August 2010, 03:35
  3. QT 4.2.3 - Size of compiled outputs
    By Declan in forum Installation and Deployment
    Replies: 1
    Last Post: 9th June 2007, 11:29
  4. cout problem
    By mickey in forum General Programming
    Replies: 3
    Last Post: 2nd March 2007, 18:12
  5. How to cout in Qt ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2006, 00:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.