python: get number without decimal places

Viewed 110805
a=123.45324

is there a function that will return just 123?

5 Answers

You can use the math.trunc() function:

a=10.2345
print(math.trunc(a))

If you want both the decimal and non-decimal part:

def split_at_decimal(num):
    integer, decimal = (int(i) for i in str(num).split(".")) 
    return integer, decimal

And then:

>>> split_at_decimal(num=5.55)
(5, 55)
Related