Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

Thursday, 27 June 2019

Different types of rounding numbers

Rounding number is useful in so many applications, that I need to mention how i works in Livecode.
We have the following function:  round(), trunc(),  ceil(), floor().Let's see how they works with examplse.
Let's tart with round(), it can round to the nearest integer or to the number o decimal indicated by the second item:

put round(2.4) # it returns 2
put round(2.6) # it returns 3 
put round(2.712, 1) # it returns 2.7
put round(2.765, 1) # it returns 2.8

The function trubc() returns onl the integer part of the number:

put trunc(2.712) # it returns 2

If we need the the nearest integer more or equal the given number, you need ceil():

put ceil(2.2321) # it returns 3

If we need the the nearest integer less or equal the given number, you need floor():

put floor(2.712) # it returns 2