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

how to round a number up in python

>>> import math

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

PREVIOUS NEXT
Code Example
Python :: pandas merge but keep certain columns 
Python :: removexa0 python 
Python :: Issue TypeError: can’t multiply sequence by non-int of type str 
Python :: multipart/form data multipart encoder python 
Python :: random picker in python 
Python :: width and height of pil image 
Python :: where are python libraries installed in windows 
Python :: read_table python 
Python :: python get first n elements of dict 
Python :: start virtual environment python 
Python :: remove specific word from string using python 
Python :: is everything in python an object 
Python :: how to save a pickle file 
Python :: pandas read from txt separtion 
Python :: Read text file line by line using the readline() function 
Python :: remove character from string by index in python 
Python :: django createmany 
Python :: python tkinter change color of main window 
Python :: where to find location of where python is installed linux 
Python :: datetime to int in pandas 
Python :: django get group users 
Python :: Python Requests Library Get Method 
Python :: unpack too many values in python 
Python :: rnadom number python 
Python :: # time delay in python script 
Python :: standard scaler vs min max scaler 
Python :: filter pandas dataframe 
Python :: read files and write into another files python 
Python :: pandas strip whitespace 
Python :: create a generator from a list 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =