QtCreator and decimal number



  • 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



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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.