Reputation: 331
How do I round up to the nearest increment of .5? Say I have
a=2.3
and want to declare b as 2.5 taking a as an input and rounding up to the nearest .5
Upvotes: 1
Views: 114
Reputation: 44699
You can use a combination of math.ceil
and simple arithmetic operations to get where you need:
import math
a = 2.3
rounded_a = math.ceil(a * 2) / 2
print(rounded_a) # 2.5
Upvotes: 1