Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

round float python

toRound = 1.0

# If a float ends in .0 to 1 decimal place, you can convert 
# it to an int without any conversions.

print(int(toRound)) # Output: 1

toRound = 1.251
# If the float isn't a whole number, then this is how you round it.

round(toRound) # Output 1 (round takes math.floor / math.ceiling into account)

# This will cause the float to automatically round to floor or ceiling if necessary 
 
PREVIOUS NEXT
Tagged: #float #python
ADD COMMENT
Topic
Name
6+5 =