Abdul Ahad
Abdul Ahad

Reputation: 31

How to separate the Full number and Decimal Number from a Divison Result in Python

For python

After division, if the result has any decimal number with the full number, I just want to get the full number and ignore the decimal number.

for example:

130/33 = 3.939393

here I just want to use the number "3" and ignore the ".939393"

How can I do that?

Thanks in advance.

Upvotes: 0

Views: 261

Answers (3)

Omkar Surve
Omkar Surve

Reputation: 11

You can use floor method of math package.

import math   
  
# prints floor() method
print(math.floor(130/33))

Output:  

3

Upvotes: 0

NicoCaldo
NicoCaldo

Reputation: 1577

You can cast to int without using any library

print(int(130/33))

Documentation about casting

Upvotes: 1

Timur Shtatland
Timur Shtatland

Reputation: 12530

Use integer division:

print(130//33)
3

SEE ALSO:

Also referred to as integer division. The resultant value is a whole integer, though the result’s type is not necessarily int. The result is always rounded towards minus infinity: 1//2 is 0, (-1)//2 is -1, 1//(-2) is -1, and (-1)//(-2) is 0

Numeric Types — int, float, complex: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex


What is the difference between '/' and '//' when used for division?

Upvotes: 2

Related Questions