Shaun Roselt
Shaun Roselt

Reputation: 3252

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

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.

Upvotes: 0

Views: 191

Answers (2)

Oskar Klimala
Oskar Klimala

Reputation: 1

use abs of () block or do it yourself like this

if (input) > 0
   set output to (input)
else:
   set output to((-1)*(input))

Upvotes: 0

Shaun Roselt
Shaun Roselt

Reputation: 3252

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

Upvotes: 2

Related Questions