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

0 favourites
  • 6 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • 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?

  • Wrong, ceil(21/20) gives 2.

  • 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!

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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!

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)