vb.net Always Positive Integer

Hello folks, I would like to know how to get a positive number all the time.

Example: 1-3 = -2  (I want  2)

So I want this: 1-3 = 2
LVL 5
nkoriginalAsked:
Who is Participating?
 
AbarajConnect With a Mentor Commented:
you can use,
Math.Abs(CInt(Textbox1.Text))
 
0
 
Paul MacDonaldDirector, Information SystemsCommented:
ABS(1-3), I think
0
 
jppintoConnect With a Mentor Commented:
This will give always int values and positive values, whatever the number are (instead of 1-3):

ABS(INT(1-3))

jppinto
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
MathiyazhaganConnect With a Mentor Commented:
use MAth.Abs function.like,


        Dim x As Integer = 1
        Dim y As Integer = 3
        Dim diff As Integer = Math.Abs(x - y)
0
 
EspavoConnect With a Mentor Commented:
Are you always going to be using Integers for the calculations?
My reason for asking is to be aware that Int() doesn't take the Integer value of the number (it kinda rounds it... thought I can't figure-out why)
Math.Abs(-Val) will give the positive answer as the replies above have said.
Espavo
0
 
sstanalandConnect With a Mentor Commented:
dim x as integer = -5
dim result as integer

result = Math.Abs(x)
0
All Courses

From novice to tech pro — start learning today.