Jump to content

Numerical difference between two numbers.


tiscavalcanti

Recommended Posts

I need make a calculation which allow know difference between two numbers. I can subtract the smallest of the larger, but this calculation is very limited, implies if a number is negative and the other positive.

 

I want to know another way to do this.

  • It is possible to do this calculation in JavaScript through the:

  1. modulo;
  2. function;
  3. (Others);

Mainly:

Another important thing which I want, is to calculate percentage difference through two differents numbers. To know the value resultant.

 

  • I want to know all the possible ways to do this. Because I came across in an embarrassing situation in a video Software that uses expressions based on the JavaScript language.

 

Thanks! :)

Edited by tiscavalcanti
Link to comment
Share on other sites

If you're trying to calculate the "distance" between two numbers as a positive value, that's the absolute value. The Math object has a method for it.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

Another important thing which I want, is to calculate percentage difference through two differents numbers. To know the value resultant.

To get the percentage difference you would take the absolute value of the difference and then divide the original number by that.
  • Like 1
Link to comment
Share on other sites

If you're trying to calculate the "distance" between two numbers as a positive value, that's the absolute value. The Math object has a method for it.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/MathTo get the percentage difference you would take the absolute value of the difference and then divide the original number by that.

You can take some examples, please?

Link to comment
Share on other sites

That MDN site has examples for all of the methods in the Math object. The other one is just some subtraction and division. Get started and ask questions if you get stuck.

I got. Examples:

 

.20*76 | 20% of 76 = 15.2

1.20*76 | 76 + 20% = 91.2

(1-.20)*76 | 76 - 20% = 60.8

 

Calculate numerical difference between two values:

 

(-8)+(3) = - 5 | balance value.

(-8)-(3) = 11 | difference value.
This is it. Thanks. :)
Edited by tiscavalcanti
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...