Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. can't get float value

can't get float value

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 4 Posters 0 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.
  • Z Offline
    Z Offline
    zhiyuan16
    wrote on last edited by
    #1

    dear all

    float nwidth = (ImageBW8 .Width / ImageBW8.ImageWidth);
    float nheight =((ImageBW8 .Height / ImageBW8.ImageHeight);

    ImageBW8 .Width ,ImageBW8.ImageWidth, ImageBW8 .Height ,ImageBW8.ImageHeight, all got value, but however nwidth and nheight are 0.0. anyone can help me? why nwidth and nheight are only 0.0, instead of exact values there. thanks a lot.

    B P L 3 Replies Last reply
    0
    • Z zhiyuan16

      dear all

      float nwidth = (ImageBW8 .Width / ImageBW8.ImageWidth);
      float nheight =((ImageBW8 .Height / ImageBW8.ImageHeight);

      ImageBW8 .Width ,ImageBW8.ImageWidth, ImageBW8 .Height ,ImageBW8.ImageHeight, all got value, but however nwidth and nheight are 0.0. anyone can help me? why nwidth and nheight are only 0.0, instead of exact values there. thanks a lot.

      B Offline
      B Offline
      Bigdeak
      wrote on last edited by
      #2

      Hi, maybe like this:

      float nwidth = Convert.ToSingle(ImageBW8.Width) / Convert.ToSingle(ImageBW8.ImageWidth);
      float nheight = Convert.ToSingle(ImageBW8.Height) / Convert.ToSingle(ImageBW8.ImageHeight);

      1 Reply Last reply
      0
      • Z zhiyuan16

        dear all

        float nwidth = (ImageBW8 .Width / ImageBW8.ImageWidth);
        float nheight =((ImageBW8 .Height / ImageBW8.ImageHeight);

        ImageBW8 .Width ,ImageBW8.ImageWidth, ImageBW8 .Height ,ImageBW8.ImageHeight, all got value, but however nwidth and nheight are 0.0. anyone can help me? why nwidth and nheight are only 0.0, instead of exact values there. thanks a lot.

        P Offline
        P Offline
        phil o
        wrote on last edited by
        #3

        Hi, You can try :

        float nwidth = (float)ImageBW8.Width / (float)ImageBW8.ImageWidth;
        float nheight = (float)ImageBW8.Height / (float)ImageBW8.ImageHeight;

        1 Reply Last reply
        0
        • Z zhiyuan16

          dear all

          float nwidth = (ImageBW8 .Width / ImageBW8.ImageWidth);
          float nheight =((ImageBW8 .Height / ImageBW8.ImageHeight);

          ImageBW8 .Width ,ImageBW8.ImageWidth, ImageBW8 .Height ,ImageBW8.ImageHeight, all got value, but however nwidth and nheight are 0.0. anyone can help me? why nwidth and nheight are only 0.0, instead of exact values there. thanks a lot.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          if those properties are integers, you get integer division. And if 0 < Width < ImageWidth, you would get zero for nwidth. You assigning the quotient to a float variable does not influence how an expression gets evaluated. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups