2
print(int( 342342342342342342 / 10 ))

The output is

34234234234234236

I do not understand where the 6 comes from! I also tried "long" which gives an error.

hengyue li
  • 448
  • 3
  • 17
  • Pretty sure it is to do with `float` Representation Error. https://docs.python.org/2/tutorial/floatingpoint.html or https://docs.python.org/3.6/tutorial/floatingpoint.html – Alex Fung Jul 25 '18 at 12:02
  • 1
    `342342342342342342 / 10` → `3.4234234234234236e+16` → [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – deceze Jul 25 '18 at 12:03

1 Answers1

1

You might be better using the integer division // operator.

print( 342342342342342342 // 10 )

As others have commented, floating points in python have some interesting results.

The common example of this is:

int(2.5)

Returns

2
CodeCupboard
  • 1,507
  • 3
  • 17
  • 26