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. Algorithms
  4. Comparing Two Values to get the percentage increase?

Comparing Two Values to get the percentage increase?

Scheduled Pinned Locked Moved Algorithms
question
11 Posts 5 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.
  • I Offline
    I Offline
    Ian Uy
    wrote on last edited by
    #1

    Hey guys, How do you compare two values and say that value 1 is X% larger than value 2 or value 1 is x fold larger than value 2? Thanks! :)

    It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

    R 1 Reply Last reply
    0
    • I Ian Uy

      Hey guys, How do you compare two values and say that value 1 is X% larger than value 2 or value 1 is x fold larger than value 2? Thanks! :)

      It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

      R Offline
      R Offline
      Robert C Cartaino
      wrote on last edited by
      #2

      Ian Uy wrote:

      How do you compare two values and say that value 1 is X% larger than value 2

      double value1 = 150.0
      double value2 = 100.0

      double difference = value1 - value2;
      double percentageIncrease = (difference / value2) * 100;

      It would be said that value1 is 50% larger than value2.

      Ian Uy wrote:

      value 1 is x fold larger than value 2

      Technically, "x fold larger" is a suffix you add to a number to say "multipled by."

      double value1 = 200.0;
      double value2 = 50.0;

      double foldIncrease = value1 / value2;

      It would be said that value1 is four-fold larger than value2. Enjoy, Robert C. Cartaino

      modified on Tuesday, August 19, 2008 4:48 PM

      I 1 Reply Last reply
      0
      • R Robert C Cartaino

        Ian Uy wrote:

        How do you compare two values and say that value 1 is X% larger than value 2

        double value1 = 150.0
        double value2 = 100.0

        double difference = value1 - value2;
        double percentageIncrease = (difference / value2) * 100;

        It would be said that value1 is 50% larger than value2.

        Ian Uy wrote:

        value 1 is x fold larger than value 2

        Technically, "x fold larger" is a suffix you add to a number to say "multipled by."

        double value1 = 200.0;
        double value2 = 50.0;

        double foldIncrease = value1 / value2;

        It would be said that value1 is four-fold larger than value2. Enjoy, Robert C. Cartaino

        modified on Tuesday, August 19, 2008 4:48 PM

        I Offline
        I Offline
        Ian Uy
        wrote on last edited by
        #3

        Uhmm. I have a problem. The two values are MILES APART and I can't find a calculator powerful enough to compute the percentage increase. Value 1 = 1.36 x 10^58 Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

        It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

        R C R 3 Replies Last reply
        0
        • I Ian Uy

          Uhmm. I have a problem. The two values are MILES APART and I can't find a calculator powerful enough to compute the percentage increase. Value 1 = 1.36 x 10^58 Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

          It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

          R Offline
          R Offline
          Robert C Cartaino
          wrote on last edited by
          #4

          Ian Uy wrote:

          Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

          The rules for addition/subtraction/multiplication/division of scientific notation are not difficult. Here is an article on Scientific Notation[^] which covers how to multiply and divide powers of ten. Here is another one[^] which also covers addition and subtraction.

          I 1 Reply Last reply
          0
          • R Robert C Cartaino

            Ian Uy wrote:

            Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

            The rules for addition/subtraction/multiplication/division of scientific notation are not difficult. Here is an article on Scientific Notation[^] which covers how to multiply and divide powers of ten. Here is another one[^] which also covers addition and subtraction.

            I Offline
            I Offline
            Ian Uy
            wrote on last edited by
            #5

            Yeah, I already did that before asking. However, I am not sure if its correct. To subtract value 1 from value 2, I need to move value 1's decimal point (19709-58)=19651 times to the right? this will produce a relatively small number. And if I subtract that small number to value 2, the result will not be different. It is still 2.36 x 10^19,709. Right?

            It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

            R 1 Reply Last reply
            0
            • I Ian Uy

              Yeah, I already did that before asking. However, I am not sure if its correct. To subtract value 1 from value 2, I need to move value 1's decimal point (19709-58)=19651 times to the right? this will produce a relatively small number. And if I subtract that small number to value 2, the result will not be different. It is still 2.36 x 10^19,709. Right?

              It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

              R Offline
              R Offline
              Robert C Cartaino
              wrote on last edited by
              #6

              Ian Uy wrote:

              this will produce a relatively small number. And if I subtract that small number to value 2, the result will not be different. It is still 2.36 x 10^19,709. Right?

              Pretty much. Consider your numbers.

              Value 2 = 2.36 x 10^19,709

              There are about 1.0 x 10^80 atoms in the known universe. If we discovered that there were actually a billion other universes out there, there would still only be 1.0 x 10^89 atoms in all of them combined. So your number (2.36 x 10^19,709) is what would be known in the mathematical community as "big... really big." Relatively speaking (compared to your first number)...

              Value 1 = 1.36 x 10^58

              ...is really, really small. Pretty much, for all intents and purposes, practically zero. So your question boils down to something like, "If I take all the matter in the in the known universe -- every tree, every person, every planet, every sun, every black hole contained in all 100-billion known galaxies -- and manage to sneeze into a parallel dimension, what percentage did I decrease the weight of the universe? And you would still be way off from your example. Enjoy, Robert C. Cartaino

              M I 2 Replies Last reply
              0
              • R Robert C Cartaino

                Ian Uy wrote:

                this will produce a relatively small number. And if I subtract that small number to value 2, the result will not be different. It is still 2.36 x 10^19,709. Right?

                Pretty much. Consider your numbers.

                Value 2 = 2.36 x 10^19,709

                There are about 1.0 x 10^80 atoms in the known universe. If we discovered that there were actually a billion other universes out there, there would still only be 1.0 x 10^89 atoms in all of them combined. So your number (2.36 x 10^19,709) is what would be known in the mathematical community as "big... really big." Relatively speaking (compared to your first number)...

                Value 1 = 1.36 x 10^58

                ...is really, really small. Pretty much, for all intents and purposes, practically zero. So your question boils down to something like, "If I take all the matter in the in the known universe -- every tree, every person, every planet, every sun, every black hole contained in all 100-billion known galaxies -- and manage to sneeze into a parallel dimension, what percentage did I decrease the weight of the universe? And you would still be way off from your example. Enjoy, Robert C. Cartaino

                M Offline
                M Offline
                Member 4194593
                wrote on last edited by
                #7

                Comparing the larger number to the smaller, it is (2.36/1.36)*10^19651 larger. 10^19728 is just less than 2^64K. This can be expressed exactly by an extended arithmetic binary number 64K BITS long, or 8K BYTES long, or 2048 DWORDS long.

                1 Reply Last reply
                0
                • I Ian Uy

                  Uhmm. I have a problem. The two values are MILES APART and I can't find a calculator powerful enough to compute the percentage increase. Value 1 = 1.36 x 10^58 Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

                  It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

                  C Offline
                  C Offline
                  cp9876
                  wrote on last edited by
                  #8

                  Ian Uy wrote:

                  Value 1 = 1.36 x 10^58 Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

                  In that case Value2 - Value1 = Value2 accurate to 19,651 decimal places. Of course, one would have to question whether percentage increase is a meaningful method of displaying the difference.

                  Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                  1 Reply Last reply
                  0
                  • R Robert C Cartaino

                    Ian Uy wrote:

                    this will produce a relatively small number. And if I subtract that small number to value 2, the result will not be different. It is still 2.36 x 10^19,709. Right?

                    Pretty much. Consider your numbers.

                    Value 2 = 2.36 x 10^19,709

                    There are about 1.0 x 10^80 atoms in the known universe. If we discovered that there were actually a billion other universes out there, there would still only be 1.0 x 10^89 atoms in all of them combined. So your number (2.36 x 10^19,709) is what would be known in the mathematical community as "big... really big." Relatively speaking (compared to your first number)...

                    Value 1 = 1.36 x 10^58

                    ...is really, really small. Pretty much, for all intents and purposes, practically zero. So your question boils down to something like, "If I take all the matter in the in the known universe -- every tree, every person, every planet, every sun, every black hole contained in all 100-billion known galaxies -- and manage to sneeze into a parallel dimension, what percentage did I decrease the weight of the universe? And you would still be way off from your example. Enjoy, Robert C. Cartaino

                    I Offline
                    I Offline
                    Ian Uy
                    wrote on last edited by
                    #9

                    Thank you for taking the time to answer my question. I understand it now. :)

                    It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

                    1 Reply Last reply
                    0
                    • I Ian Uy

                      Uhmm. I have a problem. The two values are MILES APART and I can't find a calculator powerful enough to compute the percentage increase. Value 1 = 1.36 x 10^58 Value 2 = 2.36 x 10^19,709 Is there any mathematical technique or approach to simplify this?

                      It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.

                      R Offline
                      R Offline
                      Roger Wright
                      wrote on last edited by
                      #10

                      Ian Uy wrote:

                      Is there any mathematical technique or approach to simplify this?

                      Sure! Given V1 = 1.36 x 10^58 and V2 = 2.36 x 10^19709, and %Increase = [(V2 - V1)/V1] x 100: 1. (V2 - V1)/V1 = V2/V1 - V1/V1 = V2/V1 - 1 2. V2/V1 = 10^(log V2 - log V1) 3. Subtract 1, then multiply by 100 to get % so, 1. (2.36 x 10^19709 - 1.36 x 10^58)/1.36 x 10^58 = (2.36 x 10^19709/1.36 x 10^58) - 1 2. V2/V1 = 10^(log( 2.36 x 10^19709 ) - log( 1.36 x 10^58)) = 10^ (19709.00864 - 58.13354) = 10^ 19650.87510 3. % = (10^19650.87510 -1) x 100. You're still going to have a hell of a time getting a computer to calculate a number that large, but the use of logarithms reduces the size of the intermediate results to a manageable magnitude. :)

                      "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                      M 1 Reply Last reply
                      0
                      • R Roger Wright

                        Ian Uy wrote:

                        Is there any mathematical technique or approach to simplify this?

                        Sure! Given V1 = 1.36 x 10^58 and V2 = 2.36 x 10^19709, and %Increase = [(V2 - V1)/V1] x 100: 1. (V2 - V1)/V1 = V2/V1 - V1/V1 = V2/V1 - 1 2. V2/V1 = 10^(log V2 - log V1) 3. Subtract 1, then multiply by 100 to get % so, 1. (2.36 x 10^19709 - 1.36 x 10^58)/1.36 x 10^58 = (2.36 x 10^19709/1.36 x 10^58) - 1 2. V2/V1 = 10^(log( 2.36 x 10^19709 ) - log( 1.36 x 10^58)) = 10^ (19709.00864 - 58.13354) = 10^ 19650.87510 3. % = (10^19650.87510 -1) x 100. You're still going to have a hell of a time getting a computer to calculate a number that large, but the use of logarithms reduces the size of the intermediate results to a manageable magnitude. :)

                        "A Journey of a Thousand Rest Stops Begins with a Single Movement"

                        M Offline
                        M Offline
                        Member 4194593
                        wrote on last edited by
                        #11

                        Roger Wright wrote:

                        You're still going to have a hell of a time getting a computer to calculate a number that larg

                        I beg to differ, it does not take that long. I made the calculations (I am only reporting the digit count of the various values, but I can report the actual values if desired): 14.984 msec to calculate (14,984 seconds for 1000 loops). Chars in 10^56 = 57 Chars in 136*10^56 (=V1) = 63 Chars in 10^19707 = 19708 Chars in 236*10^19707 (=V2) = 19714 Chars in (V2-V1) = 19714 Chars in quotient of (V2-V1)/V1 = 19652 Chars in remainder of (V2-V1)/V1 = 63 Chars in quotient of V2/V1 = 19652 Chars in remainder of V2/V1 = 63 Dave Augustine.

                        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