How to get the absolute value of a number in Scratch?

33 Views Asked by At

I want to get the absolute value of a number in Scratch, meaning to drop the negative sign and convert all numbers to positive numbers.

  • "-1.5" would become "1.5"
  • "-4.56E100" would become "4.56E100"
  • "-7" would become "7"
1

There are 1 best solutions below

0
Shaun Roselt On

Under the "Operators" code section, I found a block with a built-in abs function:

Scratch Abs function

So you can use it like this to get the absolute value of a number:

Scratch Absolute value of numbers