How to round down (not up)

hopscotch
help
helpwithcode

#1

Hi. I just wanted to know if, in Hopscotch, it’s possible to use math to remove decimals from a number.


#2

So what you're saying is you want to round numbers down?

3.21 -> 3
5.99 -> 5
7.5 -> 7


#3

If so, it's pretty easy. All you have to do is put this in your code:

(Random Value Here) - ((Same Random Value Here) % 1)


Fantastic Modulo(s?) and how to use It(them?)
#4

Ok, thanks! I'll try that. I think I just came up with a method, but that's easier, and will work.
EDIT: it worked, thanks!


#5

Fwiw - I typically use

Round (number - 0.5)

Note: works only for positive numbers. So I use this formula only if I know the number will be positive. Otherwise I'll use the formula Valgo already mentioned

number - (number % 1)

#6

algebra?

a-a%1


#7

Just use the purple "round" block. Then add the variable you need in the block.
This helped me in my Spiral maker thing


#8

That works, but only if the decimal is less than 0.5. If the decimal is 0.5 or greater, then it rounds up, which is not very useful for this scenario.


#9

Ah, I see. You just want to remove, not round.
Percentages are the "Modulo" button, I'm pretty sure.


#10

Yup, they are. :smiley:


#11

Oh I didn't get that either :relaxed:
So it looks like this is like "flooring", or rounding down a number.