Santosh S Kumar
Santosh S Kumar

Reputation: 479

How can I round up numbers to the next half-integer?

In Python floor() and ceil() round to the next higher or lower integer.

How to round up any value between 1.01 - 1.5 to 1.5 and 1.51 - 2.0 to 2.0 etc.?

Upvotes: 11

Views: 8477

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 601679

Multiply by two, ceil(), divide by two:

0.5 * ceil(2.0 * x)

Upvotes: 27

Related Questions