Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [solved] Statement always null
Forum Updated to NodeBB v4.3 + New Features

[solved] Statement always null

Scheduled Pinned Locked Moved C++ Gurus
2 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Matze5590
    wrote on last edited by
    #1

    Hello,

    i have a problem with a calculation. here's the code:
    @double newpos = ev->x() / 90;@

    for example ev->x() is returning '20', then newpos will be 0! its always 0!

    i also tried this:
    @double newpos = 20 / 90;@

    and the result is still always 0!

    i have no idea why... please help me!
    thanks!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Because you are dividing integers. If you want to have a floating point result, you need to cast to a floating point number before dividing:

      @
      double newPos = static_cast<double>(ev->x())/90.0;
      @

      1 Reply Last reply
      0

      • Login

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