Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python round

import math
n = 234.56

decimal_place = n - int(n)    
''' decimal_place = 234.56 - 234 = 0.56 '''

if decimal_place >= 0.5:
    print(math.ceil(n))
else: 
    print(math.floor(n))
''' Yields 234.56 --> 235 '''

''' One-Liner '''
rounded = math.ceil(n) if (n-int(n)) >= 0.5 else math.floor(n)	
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
7+7 =