How do you use absolute value in coding?



What is it and what is it used for?


Absolute value is represent by the |#| (I don't know if it's different inn the app).

It's basically making the number positive if it isn't already.


An absolute value is the opposite of the number.

For example, the absolute value of 3 is -3, anf the absolute value of 21 would be -21.
MATH LESSON- 9+10=21


It is an operator that changes any number to a positive number.
Example: 234 will stay 234, but -765 will change to 765.

hope I was right


Oh! I remember something like this in my math book! Thanks, @PopTart0219 @CreationsOfaNoob @LazyLizard what could I use it for in coding?



Maybe if you have a negative number that changes, and you need to make it positive again.


Technically incorrect; the real definition is the distance the number is from zero. :D


What Gilbert said XD

I understood the concept but I fail at explaining and doing math. :3


The distance a number is away from zero.


I'm not sure. I haven't been able to code for months, so I can't really help you with that, I'm so sorry!


Just to clarify: Absolute value is not the opposite of a number. It's the distance from 0 like rainbow chicken said.

Abs 21 = 21
Abs -21 = 21


Yah I get it now, I just forgot the term. My question is, how can I use them in coding?


A lot of things, but definitely the most important is distance. If you want to find the distance between 2 object's x positions, it's Abs(x1-x2).


That isn't really correct, |-3| is 3 and the absolute value of 3 is three :D



Ignore that! XD

Maybe I should have used the wifi when typing. I almost always get wrapped up in not getting yelled at for using the data and just let my fingers fly!