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. Java
  4. Simple Mathematics.

Simple Mathematics.

Scheduled Pinned Locked Moved Java
help
5 Posts 2 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.
  • H Offline
    H Offline
    hansoctantan
    wrote on last edited by
    #1

    Why is it giving me a zero.

    double percent = 0;
    if(condition) {
    //scrollpane is a JScrollPane and origIcon is a ImageIcon
    percent = scrollpane.getHeight() / origIcon.getImage().getHeight(scrollpane);
    System.out.print(scrollpane.getHeight() + " / " + origIcon.getImage().getHeight(scrollpane));
    System.out.println(" = " + percent);
    } else {
    //line of codes
    }

    This returns 309 / 1668 = 0.0 value should be 0.1852.. I know this is basic but I DON'T KNOW. sorry, too tired I guess but I need this to figure out Thanks

    - Be who you are and say what you feel because those who mind don't matter and those who matter don't mind. - Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.

    P 1 Reply Last reply
    0
    • H hansoctantan

      Why is it giving me a zero.

      double percent = 0;
      if(condition) {
      //scrollpane is a JScrollPane and origIcon is a ImageIcon
      percent = scrollpane.getHeight() / origIcon.getImage().getHeight(scrollpane);
      System.out.print(scrollpane.getHeight() + " / " + origIcon.getImage().getHeight(scrollpane));
      System.out.println(" = " + percent);
      } else {
      //line of codes
      }

      This returns 309 / 1668 = 0.0 value should be 0.1852.. I know this is basic but I DON'T KNOW. sorry, too tired I guess but I need this to figure out Thanks

      - Be who you are and say what you feel because those who mind don't matter and those who matter don't mind. - Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Because that's what scrollpane.getHeight() / origIcon.getImage().getHeight(scrollpane) returns, due to integer datatypes. I don't know Java, but I expect you could do something like:

      percent = scrollpane.getHeight();
      percent = percent / origIcon.getImage().getHeight(scrollpane);

      H 1 Reply Last reply
      0
      • P PIEBALDconsult

        Because that's what scrollpane.getHeight() / origIcon.getImage().getHeight(scrollpane) returns, due to integer datatypes. I don't know Java, but I expect you could do something like:

        percent = scrollpane.getHeight();
        percent = percent / origIcon.getImage().getHeight(scrollpane);

        H Offline
        H Offline
        hansoctantan
        wrote on last edited by
        #3

        well that gives me an idea.. casting should do the trick Thanks

        - Be who you are and say what you feel because those who mind don't matter and those who matter don't mind. - Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.

        P 1 Reply Last reply
        0
        • H hansoctantan

          well that gives me an idea.. casting should do the trick Thanks

          - Be who you are and say what you feel because those who mind don't matter and those who matter don't mind. - Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Yes, if done right.

          H 1 Reply Last reply
          0
          • P PIEBALDconsult

            Yes, if done right.

            H Offline
            H Offline
            hansoctantan
            wrote on last edited by
            #5

            thank you very much it works :zzz:

            - Be who you are and say what you feel because those who mind don't matter and those who matter don't mind. - Most of the problem in your life are due to two reasons: you act without thinking, or think without acting.

            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