floor of a float in python

0 votes
I have found two ways of taking floors in Python:

the first one is:

3.1415 // 1
 

and

the second one is :

import math
math.floor(3.1415)
 

The problem with the first approach is that it return a float (namely 3.0). The second approach feels clumsy and too long.Are there alternative solutions for taking floors in Python?
Nov 22, 2018 in Python by ana1504.k
• 5,910 points
29 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
As long as your numbers are positive, you can simply convert to an int to round down to the next integer:

>>> int(3.1415)
3
For negative integers, this will round up, though.
answered Nov 22, 2018 by SDeb
• 9,380 points

Related Questions In Python

+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
64 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
414 views
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
100 views
0 votes
1 answer

Sorting a list of strings in Python

Use the sort function mylist.sort() READ MORE

answered May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
11 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
19 views
0 votes
1 answer

Equivalent of a?b:c in Python

In Python 2.5, you can use ternary ...READ MORE

answered Jan 7 in Python by SDeb
• 9,380 points
11 views
0 votes
1 answer

Indentation of Python in Notepad++

To indent the block, select the entire ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 9,380 points
96 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.