Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtCreator and decimal number
Qt 6.11 is out! See what's new in the release blog

QtCreator and decimal number

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • UnitScanU Offline
    UnitScanU Offline
    UnitScan
    wrote on last edited by
    #1

    I'm working with decimal number, and this is my code:

    double fraction = 3/4;
    qDebug() << fraction
    

    Instead of 0.75, QtCreator display 0. Is a QtCreator bug, or my procedure is wrong? If so, you could tell me which is the right one?

    Thanks in advance

    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi,
      Try it with 3/4.0.
      -Michael.

      1 Reply Last reply
      3
      • R Offline
        R Offline
        raspe88
        wrote on last edited by raspe88
        #3

        You are dividing two integers. Integer-Division of a value by a larger value results to zero by definition in C++. As long as you are not making one value a double there will be no implicit cast in C++ before assigning the result to the double.

        1 Reply Last reply
        5

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved