## 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

##### 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.
• 1

##### Share on other sites

Thank you!

Edited by tiscavalcanti

##### 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?

##### 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.

##### 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.

Okay. ##### 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

##### Share on other sites

I don't really understand what you're saying, but you can use the +, -, *, and / operators to do basic math.

##### Share on other sites

I don't really understand what you're saying, but you can use the +, -, *, and / operators to do basic math.

Good, you is right, Thank You!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.