0

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.

Abdul Ahad
  • 21
  • 1
  • 3
  • Does this answer your question? [What is the difference between '/' and '//' when used for division?](https://stackoverflow.com/questions/183853/what-is-the-difference-between-and-when-used-for-division) – TheFungusAmongUs Jul 20 '22 at 15:30
  • 1
    Does this answer your question? [How to divide without remainders on Python](https://stackoverflow.com/questions/34906753/how-to-divide-without-remainders-on-python) – 9769953 Jul 20 '22 at 15:30
  • 1
    Do you want it rounded up, down, closest full number or literally take the integer number as it is before the decimal place? – Johnny John Boy Jul 21 '22 at 08:35

3 Answers3

2

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?

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
  • 2
    The problem with this solution is that `-130//33` will result in `-4` which is most likely undesired behavior. Converting to int with `int(-130/33)` removes the precision and results in `-3`. – ericksonb Jul 20 '22 at 15:36
1

You can cast to int without using any library

print(int(130/33))

Documentation about casting

NicoCaldo
  • 1,171
  • 13
  • 25
  • 1
    If it's any consolation, I think this is the right answer as the OP asked specifically for the number before the decimal place. int(str(number).split('.')[0]) would be the long way of doing what they, in my opinion, are asking. – Johnny John Boy Jul 21 '22 at 08:37
0

You can use floor method of math package.

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

Output:  

3