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 2put round(2.6) # it returns 3 put round(2.712, 1) # it returns 2.7put round(2.765, 1) # it returns 2.8The function trubc() returns onl the integer part of the number:
put trunc(2.712) # it returns 2If we need the the nearest integer more or equal the given number, you need ceil():
put ceil(2.2321) # it returns 3If we need the the nearest integer less or equal the given number, you need floor():
put floor(2.712) # it returns 2
No comments:
Post a Comment