# VB.Net is there a function to return the difference between two values?

I need to compare a zero or greater value to a value that may be negative and return the difference between the two values as a positive number  these variables are all stored as data type Double.

For example:

Value 1 = 17
Value 2 = -4

Would like function to return 21.

Thanks,
Jon
###### Who is Participating?

Commented:
Sure ;-)

Diff = Math.Abs(Value1-Value2)

All joking aside, the short answer is no.  However, you could easily write your own.

Public Function Diff(ByVal Value1 As Double, ByVal Value2 As Double) As Double
Return Math.Abs(Value1 - Value2)
End Function
0

Author Commented:
I ended up turning the negative number value2 into a positive and adding to value1.

If FutureBalance < OrderPoint And FutureBalance < 0 Then
FutureSuggOrder = Math.Abs(FutureBalance) + OrderPoint
ElseIf FutureBalance < OrderPoint And FutureBalance >= 0 Then
FutureSuggOrder = OrderPoint - FutureBalance
Else
FutureSuggOrder = 0
End If
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.