Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python round up

>>> import math

>>> math.ceil(5.2)
6

>>> math.ceil(5)
5

>>> math.ceil(-0.5)
0
Comment

round up division python

# no import needed
# take advantage of floor division by negating a and flooring it
# then negate result to get a positive / negative (depending on input a)

def round_up(a, b = 1):
  return -(-a // b) # wrap in int() if only want integers

>>> round_up(3.2) # works on single digits
4.0
>>> round_up(5, 2)
3
>>> round_up(-10, 4) # works on negative numbers
-2
Comment

round down a number python

#math.floor(number)

import math
print(math.floor(3.319))  #Prints 3
print(math.floor(7.9998)) #Prints 7
Comment

python round down

>>>import math
>>> math.floor(1.6)
1
>>> math.floor(2)
2
>>> math.floor(3.9)
3
Comment

python round down

>>> int(1.6)
1
>>> int(2)
2
>>> int(3.9)
3
Comment

how to round a number up in python

>>> import math

>>> math.ceil(3.2) # round up
4
Comment

round down number python

#int('your decimal number')
>>>> int(1.7)
1
Comment

PREVIOUS NEXT
Code Example
Python :: print a to z in python 
Python :: python list to string with spaces 
Python :: create directory python if not exist 
Python :: pandas count nan in each row 
Python :: how to close the window in pygame 
Python :: count the frequency of words in a file 
Python :: python convert datetime.timedelta into seconds 
Python :: python how to make a server 
Python :: messages django 
Python :: vs code run python in terminal invalid syntax 
Python :: how to convert list into string in python 
Python :: how to check if a message includes a word discord.py 
Python :: how to reverse a list in python using for loop 
Python :: python windows take screenshot pil 
Python :: reverse linked list with python 
Python :: How to find majority element in a sequence of values using Boyer-Moore vote algorithm? 
Python :: discord.py commands.group 
Python :: how to make game on python 
Python :: remove trailing and leading spaces in python 
Python :: django.db.utils.OperationalError: no such table: 
Python :: python multiply list bt number 
Python :: how to remove python3 on mac 
Python :: drop second column pandas 
Python :: python little endian to big endian 
Python :: python how to get directory of script 
Python :: save strings with numpy savetext 
Python :: pandas scatter plot with different colors 
Python :: You did not provide the "FLASK_APP" environment variable 
Python :: pygame.set_volume(2.0) max volume 
Python :: pandas change frequency of datetimeindex 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =