Typecasting to 'int' in Python generating wrong result -


i tried performing following typecast operation in python 3.3

int( 10**23 / 10 )

output: 10000000000000000000000

and after increasing power 1 or further

int( 10**24 / 10 )

output: 99999999999999991611392

int( 10**25 / 10 )

output: 999999999999999983222784

why happening? although simple typecasting like

int( 10**24 )

output: 1000000000000000000000000

is not affecting values.

you doing floating-point division / operator. 10**24/10 happens have inexact integer representation.

if need integer result, divide //.

>>> type(10**24/10) <class 'float'> >>> type(10**24//10) <class 'int'> 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -