-3

Is there any way to convert a floating point number in Python to an integer except math.floor()?

I have already tried math.floor(), but I am getting an error says:

Cannot import math

Any other way?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
A J
  • 107
  • 7

2 Answers2

1

Use the int() function

print int(5.3) # "5"

For more info

myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33
0

You can:

  • Use int(3.14)
  • import math then math.floor(3.14) or math.ceil(3.14) (depending on which way you want to round) (you said this doesn't work but I'll leave it for reference)
  • x = x - x % 1 or x -= x % 1
Arc676
  • 4,445
  • 3
  • 28
  • 44