# How do I round up a number to the nearest hundredths? (n.00)

Get help using Construct 2

### » Sat Jul 04, 2015 9:59 am

Using ceil(), it seems this rounds up a number only to the 10ths, while I want them up to the 100ths.
ex) ceil(21/20) = ceil(1.05) = 1, while I need 2 for that.
How can I make it round up to 100ths?
B
14
S
3
Posts: 31
Reputation: 937

### » Sat Jul 04, 2015 10:07 am

Wrong, ceil(21/20) gives 2.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

### » Sat Jul 04, 2015 12:04 pm

mindfaQ wrote:Wrong, ceil(21/20) gives 2.

Really??? Then I must have missed or misunderstood something in the test...... got to check again. Thanks for the reply!
B
14
S
3
Posts: 31
Reputation: 937

### » Sun Jul 05, 2015 2:25 am

Try (round((21/20)*100)/100

This will divide 21 by 20, giving you 1.05, multiply it by 100 to give you 105, round to closest integer (if it wasn't already an integer) and then divide by 100 to give you 1.05.
B
8
S
2
Posts: 35
Reputation: 572

### » Sun Jul 05, 2015 10:23 am

Drakkith wrote:Try (round((21/20)*100)/100

This will divide 21 by 20, giving you 1.05, multiply it by 100 to give you 105, round to closest integer (if it wasn't already an integer) and then divide by 100 to give you 1.05.

I think this isn't matching with my needs right now, but your explanation for the formula makes my thoughts much clearer. Thanks for the tip!
B
14
S
3
Posts: 31
Reputation: 937

### » Sun Jul 05, 2015 10:37 am

I found the mistake! In the ceil(), I was dividing a variable which contains the value of loopindex, which starts from 0.
ex) ceil(Variable_of_loopindex/n)
So this became ceil(0/20) = 0, while I was thinking it should be ceil(1/20) = 0.05.
Simple mistake caused by being unfamiliar with 0-based index!
B
14
S
3
Posts: 31
Reputation: 937