{"id":24070,"date":"2021-10-14T09:12:54","date_gmt":"2021-10-14T03:42:54","guid":{"rendered":"https:\/\/python-programs.com\/?p=24070"},"modified":"2021-11-05T20:53:17","modified_gmt":"2021-11-05T15:23:17","slug":"python-program-for-floor-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-floor-function\/","title":{"rendered":"Python Program for floor() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for fabs() Function<\/a> If necessary, the math.floor() method rounds a number DOWN<\/strong> to the nearest integer and returns the result.<\/p>\n The python math. floor() function returns the nearest integer value that is less than or equal to the specified expression or Value.<\/p>\n Syntax:<\/strong><\/p>\n Parameter Values:<\/strong><\/p>\n number: This is required. It Sets the number to round down.<\/p>\n Return Value: <\/strong>The return value is an int value that represents the rounded number.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Read all the mathematical functions available in Python and understand how to implement them in your program by using the tutorial of Python Mathematical Methods Examples<\/a>.<\/p>\n In the previous article, we have discussed Python Program for fabs() Function floor() Function in Python: If necessary, the math.floor() method rounds a number DOWN to the nearest integer and returns the result. The python math. floor() function returns the nearest integer value that is less than or equal to the specified expression or Value. …<\/p>\n
\nfloor() Function in Python:<\/strong><\/p>\nmath.floor(number)<\/pre>\n
Given tuple = (1.3, 10.04, -4.4, 7.7, 9.45)\r\nGiven List = [2.8, 3.4, -1.7, -6.82, 12.2]<\/pre>\n
Given positive number 9.2 floor value = 9.00\r\nGiven negative number -8.6 floor value = -9.00\r\nGiven Tuple element(gvn_tupl[3]) floor value = 7.00\r\nGiven Tuple element(gvn_lst[2]) floor value = -2.00\r\nThe floor of pi is: 3\r\nGiven multiple number(35+40-10.3) floor value = 64.00<\/pre>\n
Given tuple = (2.4, 85.67, 37.8, -25.5)\r\nGiven List = [45.9, 11.32, -25, 6, 12.8, -10]<\/pre>\n
Given positive number 30.1 floor value = 30.00\r\nGiven negative number -20.4 floor value = -21.00\r\nGiven Tuple element(gvn_tupl[0]) floor value = 2.00\r\nGiven Tuple element(gvn_lst[3]) floor value = 6.00\r\nThe floor of pi is: 3\r\nGiven multiple number(23-10+5) floor value = 18.00<\/pre>\n
Program for floor() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the tuple as static input and store it in a variable.\r\ngvn_tupl = (1.3, 10.04, -4.4, 7.7, 9.45)\r\n# Give the list as static input and store it in another variable.\r\ngvn_lst = [2.8, 3.4, -1.7, -6.82, 12.2]\r\n# Apply math. floor() function to any positive number and print it.\r\nprint('Given positive number 9.2 floor value = %.2f' % math.floor(9.2))\r\n# Apply math. floor() function to any negative number and print it.\r\nprint('Given negative number -8.6 floor value = %.2f' % math.floor(-8.6))\r\n# Apply math. floor() function to the given tuple element and print it.\r\nprint('Given Tuple element(gvn_tupl[3]) floor value = %.2f' % math.floor(\r\n gvn_tupl[3]))\r\n# Apply math. floor() function to the given list element and print it.\r\nprint(\r\n 'Given Tuple element(gvn_lst[2]) floor value = %.2f' % math.floor(gvn_lst[2]))\r\n# Apply math. floor() function to the pi value and print it.\r\nprint(\"The floor of pi is: \", math.floor(math.pi))\r\n# Apply math. floor() function to any multiple numbers and print it.\r\nprint('Given multiple number(35+40-10.3) floor value = %.2f' %\r\n math.floor(35+40-10.3))\r\n<\/pre>\n
Given positive number 9.2 floor value = 9.00\r\nGiven negative number -8.6 floor value = -9.00\r\nGiven Tuple element(gvn_tupl[3]) floor value = 7.00\r\nGiven Tuple element(gvn_lst[2]) floor value = -2.00\r\nThe floor of pi is: 3\r\nGiven multiple number(35+40-10.3) floor value = 64.00<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the tuple as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_tupl = tuple(map(float, input(\r\n 'Enter some random tuple Elements separated by spaces = ').split()))\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in another variable.\r\ngvn_lst = list(map(float, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give the positive number as user input using the float(input()) function and\r\n# Store it in another variable.\r\ngvn_positvenum=float(input(\"Enter some random number = \"))\r\n# Apply math. floor() function to the given positive number and print it.\r\nprint('Given positive number',gvn_positvenum,'floor value = %.2f' % math.floor(gvn_positvenum))\r\n# # Give the negative number as user input using the float(input()) function and\r\n# Store it in another variable.\r\ngvn_negatvenum=float(input(\"Enter some random number = \"))\r\n# Apply math. floor() function to the given negative number and print it.\r\nprint('Given negative number',gvn_negatvenum,' floor value = %.2f' % math.floor(gvn_negatvenum))\r\n# Apply math. floor() function to the given tuple element and print it.\r\nprint('Given Tuple element(gvn_tupl[0]) floor value = %.2f' % math.floor(\r\n gvn_tupl[0]))\r\n# Apply math. floor() function to the given list element and print it.\r\nprint(\r\n 'Given Tuple element(gvn_lst[3]) floor value = %.2f' % math.floor(gvn_lst[3]))<\/pre>\n
Enter some random tuple Elements separated by spaces = 26.4 10.8 -11.23 -10.7\r\nEnter some random List Elements separated by spaces = 89 45.2 65.3 96.8\r\nEnter some random number = 54.3\r\nGiven positive number 54.3 floor value = 54.00\r\nEnter some random number = -10.5\r\nGiven negative number -10.5 floor value = -11.00\r\nGiven Tuple element(gvn_tupl[0]) floor value = 26.00\r\nGiven Tuple element(gvn_lst[3]) floor value = 96.00<\/pre>\n
\n