[SOLVED]Round a number to the nearest multiple..

Get help using Construct 2

Post » Sat Nov 05, 2011 2:20 pm

Het all!

Today it's about Maths, and well my brain crash down when it's about Maths.

Here's the problem:

I've a first number whose value is determined by the X position of the mouse. (We call it a)
I've a second number who is always even. (We'll call b)

a and b are integer.

How to round up or down a to the nearest multiple of b?

If someone wanna help me, or teach me!wilfryed2011-11-05 15:29:15
B
23
S
5
G
5
Posts: 112
Reputation: 4,737

Post » Sat Nov 05, 2011 2:26 pm

RoundedX = round( MouseX / GridX ) * GridX

Basically, first you divide the mouse X position by that even number, then you multiply it by that even number.

In some cases you may want to use floor or ceil instead of round (for rounding up or down).
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Nov 05, 2011 3:27 pm

Hurray!

You're my favorite mathematician ahah!
B
23
S
5
G
5
Posts: 112
Reputation: 4,737


Return to How do I....?

Who is online

Users browsing this forum: Magistross, mallorcaredes, PavleNikolic and 26 guests