How to simulate C style integer division?

Grobu snailcoder at retrosite.invalid
Thu Jan 21 20:59:53 EST 2016


On 21/01/16 09:39, Shiyao Ma wrote:
> Hi,
>
> I wanna simulate C style integer division in Python3.
>
> So far what I've got is:
> # a, b = 3, 4
>
> import math
> result = float(a) / b
> if result > 0:
>    result = math.floor(result)
> else:
>    result = math.ceil(result)
>
>
> I found it's too laborious. Any quick way?
>

math.trunc( float(a) / b )




More information about the Python-list mailing list