Calculate difference between two numbers and get absolute value


distressed:

I want to find the difference between two numbers in Go, the result should not be in "-".

Please find my code below:

    dollarValue := 240000 - 480000  

The result is "-240000". But my expected output is only "240000". Can anyone help how to calculate the difference between these two numbers.

Manh Quyet Nguyen:

Your title is misleading. It should be in the state of not negativehaving it instead - operator.

Basically what you want to get is the absolute difference between two numbers

You have two options:

  • If the result is negative, use if/else condition to return a positive result
  • use (requires conversion from/to float)math.Abs

Related


Javascript function to get the difference between two numbers

Mithun Sreedharan I want a simple Javascript function to get the difference between two numbers in such a way that foo(2, 3)sum foo(3,2) returns the same difference of 1. mykhal: var difference = function (a, b) { return Math.abs(a - b); }

Calculate the absolute difference between two angles

Daniel I have two angles a and b and I want to calculate the absolute difference between the two angles. example >> absDiffDeg(360,5) ans = 5 >> absDiffDeg(-5,5) ans = 10 >> absDiffDeg(5,-5) ans = 10 toss Normalize the difference, because mod(x,y) takes the s

Get the difference in digits between two numbers

Parry For a simple command line tool, I want to draw a simple graph showing some points and their y-axis values. For the y-axis labels, I want to print the level of the current "row", for example: 55,09| | 54,90| || 54,70| || 54,51| || 54,32| || 54,13| |

Javascript function to get the difference between two numbers

Mithun Sreedharan I want a simple Javascript function to get the difference between two numbers in such a way that foo(2, 3)sum foo(3,2) returns the same difference of 1. mykhal: var difference = function (a, b) { return Math.abs(a - b); }

Calculate difference between two numbers and get absolute value

distressed: I want to find the difference between two numbers in Go, the result should not be in "-". Please find my code below: dollarValue := 240000 - 480000 The result is "-240000". But my expected output is only "240000". Can anyone help how to calc

Calculate value between two numbers (Google Sheets)

Brondby If the smallest number is 15 and the largest number is 200 , what formula do I need to use to define a multiplication pattern that applies the 28 values needed to complete that multiplication table? I want to learn how to create this pattern to use, I

PHP calculate percentage difference between two numbers

Sanju I am trying to find the percentage difference of two numbers. The reality is that iam gets the total value of user data for this week and last week. Now I need to see the percent difference in performance between this week's data and last week's data. Be

Calculate the absolute difference between two angles

Daniel I have two angles a and b and I want to calculate the absolute difference between the two angles. example >> absDiffDeg(360,5) ans = 5 >> absDiffDeg(-5,5) ans = 10 >> absDiffDeg(5,-5) ans = 10 toss Normalize the difference, because mod(x,y) takes the s

Get the difference in digits between two numbers

Parry For a simple command line tool, I want to draw a simple graph showing some points and their y-axis values. For the y-axis labels, I want to print the level of the current "row", for example: 55,09| | 54,90| || 54,70| || 54,51| || 54,32| || 54,13| |

Get the difference in digits between two numbers

Parry For a simple command line tool, I want to draw a simple graph showing some points and their y-axis values. For the y-axis labels, I want to print the level of the current "row", for example: 55,09| | 54,90| || 54,70| || 54,51| || 54,32| || 54,13| |

Unable to calculate percentage difference between two numbers

LyonsTheWay2Gold I am trying to display a percentage after subtracting a number. example: Job Cost = £165.00Worker Charges = £42.00Surplus =% What percentage of costs are left after workers take a pay cut? My code output shows 0 int number = 0, number1, result

How to find absolute difference between two numbers

User 1145643 What is the best way to find the absolute difference between two numbers in MYSQL so that the results can be sorted? The following works only if numberA is greater than numberB, but as you can see this is not always the case. Is there a good way t

Get percentage difference between two numbers JavaScript

John I need to get the percentage between two numbers like YouTube (likes and dislikes). YouTube gets the number of likes and dislikes to set the percentage of the progress bar, as shown below: I need to do something the same. I have tried doing this but faile

How to get the absolute difference of two numbers?

Sanjit Jr Is there a bash/shell command to get the absolute difference of two numbers? E.g. - absolute diff -10 and -5 is 5, -10 and 10 is 20, 7 and 21 is 14and 100 and -11 is 111. Or is there any work to find it? please help. green Here is a simple one: echo

Calculate difference between two numbers and get absolute value

distressed: I want to find the difference between two numbers in Go, the result should not be in "-". Please find my code below: dollarValue := 240000 - 480000 The result is "-240000". But my expected output is only "240000". Can anyone help how to calc

Calculate value between two numbers (Google Sheets)

Brondby If the smallest number is 15 and the largest number is 200 , what formula do I need to use to define a multiplication pattern that applies the 28 values needed to complete that multiplication table? I want to learn how to create this pattern to use, I

Calculate value between two numbers (Google Sheets)

Brondby If the smallest number is 15 and the largest number is 200 , what formula do I need to use to define a multiplication pattern that applies the 28 values needed to complete that multiplication table? I want to learn how to create this pattern to use, I

Calculate the absolute difference between two angles

Daniel I have two angles a and b and I want to calculate the absolute difference between the two angles. example >> absDiffDeg(360,5) ans = 5 >> absDiffDeg(-5,5) ans = 10 >> absDiffDeg(5,-5) ans = 10 toss Normalize the difference, because mod(x,y) takes the s

PHP calculate percentage difference between two numbers

Sanju I am trying to find the percentage difference of two numbers. The reality is that iam gets the total value of user data for this week and last week. Now I need to see the percent difference in performance between this week's data and last week's data. Be

Unable to calculate percentage difference between two numbers

LyonsTheWay2Gold I am trying to display a percentage after subtracting a number. example: Job Cost = £165.00Worker Charges = £42.00Surplus =% What percentage of costs are left after workers take a pay cut? My code output shows 0 int number = 0, number1, result

Calculate value between two numbers (Google Sheets)

Brondby If the smallest number is 15 and the largest number is 200 , what formula do I need to use to define a multiplication pattern that applies the 28 values needed to complete that multiplication table? I want to learn how to create this pattern to use, I

Calculate value between two numbers (Google Sheets)

Brondby If the smallest number is 15 and the largest number is 200 , what formula do I need to use to define a multiplication pattern that applies the 28 values needed to complete that multiplication table? I want to learn how to create this pattern to use, I

How to get the absolute difference of two numbers?

Sanjit Jr Is there a bash/shell command to get the absolute difference of two numbers? E.g. - absolute diff -10 and -5 is 5, -10 and 10 is 20, 7 and 21 is 14and 100 and -11 is 111. Or is there any work to find it? please help. green Here is a simple one: echo