expression needed to round number

Get help using Construct 2

Post » Tue Feb 16, 2016 9:20 am

how do i round number 6,879 to 6,88 ?

i know only that expressions:
floor
round
ciel (dont work)
is any other to use??
B
109
S
25
G
43
Posts: 1,883
Reputation: 33,553

Post » Tue Feb 16, 2016 9:41 am

Maybe the answer is to easy:

x= 6,879

round(x*100)/100
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Tue Feb 16, 2016 9:49 am

The actual expression is spelled "Ceil()" and it will round to the upper integer.
In doubts always refer to the system expressions manual article.

@Asmodean formula is the best answer for your actual question.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483

Post » Tue Feb 16, 2016 9:58 am

@Asmodean that works perfecct :)
B
109
S
25
G
43
Posts: 1,883
Reputation: 33,553

Post » Tue Feb 16, 2016 10:00 am

@Kyatric and is @ Asmodean are both correct.

Ceil() is great for rounding up integers while floor() is great to round down integers.

Take your value x and use (floor(x*100)/100), granted round will do the same in this example; but floor is better for if the number has lots of decimals.
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Tue Feb 16, 2016 10:09 am

@emodaeden: Indeed floor() has an impact on the number of decimals.
But it also impacts the result, whether the last decimal is greater than 5 or not, when using "floor" the returned number will always be rounded down, whereas "round" allows to have a distribution in both direction (down if the last decimal is less than 5, up if it is 5 or more).

To impact on the number of decimals you want, modify the value "100" to bigger, depending on the decimals you need.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483


Return to How do I....?

Who is online

Users browsing this forum: el3um4s, marcoscodas, TylerJS and 9 guests