difference between floor() and rounddown() function

Certified Senior Developer

what is the difference between floor() and rounddown() function or ceiling() and roundup() function ?

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer
    Hi paragk998,

    Floor()--- It Rounds the number down to the nearest multiple of the specified significance.

    ceiling()---It Rounds the number up to the nearest multiple of the specified significance.

    rounddown()--- It Rounds the number down to the specified digit.

    roundup()---It Rounds the number up to the specified digit
  • Hello,
    floor:-The floor function functionality is to just give the number of digits which we had give after the decimal.
    for eg :- floor(2.88888, .001)== 2.888 (this function will not give the round of values only provide same digits)

    Rounddown():- this function is also to give the number fo digits after the decimal without any change in the value.
    for eg:- rounddown(2.1298,2)== 2.12 or rounddown(2.1211,2)== 2.12,

    RoundUp():- this function will give the nearest round of depend on the last digit of the value we required.
    for eg:- round(2.1298,2) or roundup(2.1218,2) == 2.13 and roundup(2.1200)= 2.12, so if the digit next to the digit we required is 0 then output will be same otherwise the value will me increaser by 1 added in the last digit.
    roundup(2.192)= 2.2

    ceiling()= This function will give the next number value and after the decimal if all the digits are 0 then the output will be the same otherwise the output will be the next number. Also you can define that it has to give add +1 or +.5 according to the value after decimal
    for eg:- ceiling(2.00)= 2, ceiling(2.01)= 3 (by default the increment value is +1)
    for eg:- ceiling(2.00,.5)=2, ceiling(2.01,.5)= 2.5,ceiling(2.50,.5)= 2.5,ceiling(2.512)= 3, ceiling(2.65)= 3

    Hope this will help you.

    Thanks
    Sahil Batra
  • 0
    Certified Lead Developer
    Hi,

    floor() rounds the number down to the nearest multiple of the specified significance. i.e. The number will be rounded to the highest multiple of the significance that is less than the number.
    for eg.
    floor(2.8888,2) will give you 2 because the highest multiple of the significance (2) which is less than 2.8888 is 2 X 1= 2.
    In the same example if you make the significance as 3 , the result will be 0 because the highest multiple of 3 which is less than 2.8888 is
    3 X 0=0.
    rounddown() function rounds the number down to the specified digit and has nothing to do with significance as in case of floor().
    for eg.
    round(2.8888, 2) will give you 2.89
    round(2.8888, 3) will give you 2.889
    in this example , 2 and 3 represents the digit or place to which the number will be rounded down to the nearest 10^(-num_digits) and not the significance as in case of floor().

    The ceiling() function rounds the number up to the nearest multiple of the specified significance but in case of ceiling, the number will be rounded to the lowest multiple of the significance that is greater than the number.
    for eg. ceiling(2.8888,2) will give you 4 as 4 is the lowest multiple of 2 (the significance) which is greater than 2.8888.
    and ceiling(2.8888,3) will give you 3 as 3 is the is the lowest multiple of 3 (the significance) which is greater than 2.8888.

    roundup() function rounds the number up to the specified digit and has nothing to do with significance as in case of ceiling().
    round(2.8888, 2) will give you 2.89
    round(2.8888, 3) will give you 2.889
    in this example , 2 and 3 represents the digit or place to which the number will be rounded up to the nearest 10^(-num_digits) and not the significance as in case of floor().
  • Here are a few examples for better understanding

    floor(9.46896, .01)-9.46
    rounddown(9.46896,.01)-9

    ceiling(9.46896,.01)-9.47
    roundup(9.46896,.01)-10
  • Hi paragk998,

    1) floor() : Rounds the number down to the nearest multiple of the specified significance.
    It takes two parameters, floor( number, significance)
    For Example:
    floor(35.254698) returns 35.
    If we specify the significance , then the number will be rounded to the highest multiple of the significance that is less than the number.
    For example, floor(-7,5) = -10, because -10 is the highest multiple of 5 that is less than -7. The default value is 1.0.

    Examples:
    floor(35.2546,10) returns 30
    floor(35.2546,2) returns 34
    floor(35.2546,6) returns 30
    floor(35.2546,4) returns 32

    2) rounddown(): Rounds the number down to the specified digit

    Examples:
    rounddown(54.22255,0) returns 54
    rounddown(54.22255,1) returns 54.2
    rounddown(54.22255,2) returns 54.22
    rounddown(54.22255,5) returns 54.22255
    rounddown(54.22255,6) returns 54.22255

    3) ceiling(): Rounds the number up to the nearest multiple of the specified significance.

    Eaxmples:
    ceiling(2.3) returns 3
    ceiling(7.32,.5) returns 7.5
    ceiling(35.254698) returns 36

    4) roundup() : Rounds the number up to the specified digit.

    Examples:
    round(2.8888, 1) returns 2.9
    roundup(7.36819) returns 7.37
    roundup(7.36819, 3) returns 7.369
    roundup(7.36819, 4) returns 7.3682

    Once check the documentaion on Mathematical Functions so that you will get clear information.

    Hope this helpful.

    Regards,

    Aswini
  • Hi paragk998 ,

    1.Floor() and Rounddown()

    Floor()

    Basically the floor function takes as input a real number x and gives as output the greatest integer less than or equal to x.

    For e.g. floor(2.8888) will return 2

    x Floor X Ceiling X  
    2 2 2  
    2.4 2 3  
    2.9 2 3  
    −2.7 −3 −2  
    −2 −2 −2  

    Rounddown()

    And Rounddown() rounds the number down to the specified digit. 

    rounddownnumber, [num_digits] )

    number: (Decimal) The number to be rounded.

    num_digits: (Integer) Determines the digit or place to which the number will be rounded down to the nearest 10^(-num_digits). 2 is default.

     For e.g.

    rounddown(7.36819) returns 7.36

    rounddown(7.36819, 3) returns 7.368

    rounddown(7.36879, 3) returns 7.368

    rounddown(7.36819, 4) returns 7.3681 

    2.Ceiling() and Roundup()

    Ceiling()

    The ceiling function maps X to the least integer greater than or equal to X

    For e.g. ceiling (2.8888) will return 3

    Roundup()

    Rounds the number up to the specified digit.

    roundupnumbernum_digits )

    number: (Decimal) The number to be rounded.

    num_digits: (Number) Determines the digit or place to which the number will be rounded up to the nearest 10^(-num_digits). 2 is default.

     For e.g.
     

    roundup(7.36819) returns 7.37

    roundup(7.36819, 3) returns 7.369

    roundup(7.36819, 4) returns 7.3682

  • Hi Parag,

    floor() & ceiling() function is vice-versa to each other, i.e in floor() function , floor(2.90,.5)=2.5 because 2.5 is the down to nearest multiple of .5 and in the same way ceiling(2.90,.5) return 3 because 3 is up to nearest multiple of .5.

    Regards
    Abhay
  • floor:
    In floor(20,5) will give the nearest multiple of 5 which is less than or equal to the given number ie 20
    for floor(13,5) it gives 10
    ceiling:
    ceiling(12.8) round to the next integer ie 13
    rounddown:
    roundup:
    roundup( number, [num_digits] )
    roundup(2.123456, 1) will round to 2.2
    roundup(2.123456, 2) will round to 2.13
    roundup(2.123456, 3) will round to 2.124
    roundup(2.123456, 4) will round to 2.1235
    roundup(2.123456, 5) will round to 2.12346
    it rounds the nth digit after the decimal point to the next value and displays the same value till that nth precision
    ex:roundup(2.123456, 3)-->2.124
    but
    if [num digits] is grater-than or equal to the max precision it will give the same number
    ex:
    roundup(2.123456, 6) will round to 2.123456
    roundup(2.123456, 9) will round to 2.123456

    rounddown:
    rounddown( number, [num_digits] )
    it simply display till the nth precision
    ex:
    rounddown( 2.123456,3) rounds to 2.123
  • Hi parag,

    floor() :- Rounds the number down to the nearest multiple of the specified significance.

    floor(2.8888, .0124568) returns 2.877521
    floor(-7,5) returns -10

    rounddown() :- Rounds the number down to the specified digit.

    rounddown(7.36819) returns 7.36

    rounddown(7.36819, 3) returns 7.368

    rounddown(7.36819, 4) returns 7.3681


    ceiling() :- Rounds the number up to the nearest multiple of the specified significance.

    ceiling(7.32,.5) returns 7.5

    ceiling(1.6) returns 2

     

     roundup() :- Rounds the number up to the specified digit.

    roundup(7.36819) returns 7.37

    roundup(7.36819, 3) returns 7.369

    roundup(7.36819, 4) returns 7.3682

  • Hi paragk,

    Floor() function relies on 2 parameters called (Number, Significance).Here significance rounds the highest multiple of the significance(decimal) which is less than a number.For example:
    floor(2.8888, .01) returns 2.88 and the result set is same for the significance values .01,.02,.03,.04 i.e,floor(2.8888, .04) returns 2.88 while it varies for floor(2.8888,.05) as 2.85 that means the value is getting rounded to the nearest multiple of the significance.

    rounddown() also expects 2 parameters called (Number,num_digits) Number is of decimal type which rounds the number to specific digit.
    Example; round(1.8888, 0) returns 2,
    round(1.8888, 1) returns 1.9.If there is a case to round down a number to the nearest hundred in such case set the second parameter of rounddown() to -2.

    Another case is like , when you need a desired result use fixed() function with rounddown() i.e, fixed( 5.6567) returns 5.66.

    ceiling(number,significance) returns the lowest multiple value of the significance which is greater than the number.
    Example:ceiling(1.5) returns 2
    ceiling(1.5,.05) returns 1.5

    roundup(number, num_digits ) rounds the number up to nearest hundred .
    Example: round(1.8888, 1) returns 1.9
    round(1.8888, 2) returns 1.89

    As rounddown() function use fixed() to get the desired result.


    Thanks,
    ravalik