Round?

For questions about using Classic.

Post » Sun May 25, 2008 10:13 pm

How do you use the "round" command?
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Sun May 25, 2008 10:33 pm

The 'round' expression? It just rounds a floating point number to the nearest whole number. Eg. round(0.7) = 1, round(6.3) = 6. It was missing from System Expressions on the wiki, so I added it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon May 26, 2008 12:12 am

oh... I thought it could be used for grids. Like round 29 to closest 32.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Mon May 26, 2008 2:58 pm

You can also use it for that, to round x to the nearest multiple of 32 is something like:

round(x / 32) * 32

If the alignment is wrong try floor(x / 32) * 32.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue May 27, 2008 3:01 pm

Ok thanks! Since mmf didn't use decimals i was used to do just X/32*32.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Tue May 27, 2008 6:04 pm

It's worth noting that division defaults to floating point calculation in Construct - you have to explicitly use Round or Int to specify integer operations (which is opposite to MMF where you explicitly specify when you want to use float operations).
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests