Python 3 with large integers

Ken Ma

I use Python to handle some large integers (64-bit, unsigned). I'm trying to convert a string of values to integers. However my Python3 gave me incorrect results. For example, if I convert an input string of "12736193479609682490" to integer, the result is not what I expected:

a = '12736193479609682490'
b = int(float(a))

>>>b
12736193479609681920

I'm usng Python 3.4.0 under ubuntu 12.04-64bit. What should I do to make a correct conversion? Thanks.

wim

Don't convert to float first.

>>> int("12736193479609682490")
12736193479609682490

That number is too big to store in a float accurately!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Handling large integers in python

From Dev

Handling large integers in python

From Dev

Distinguishing large integers from near integers in python

From Dev

How does python represent such large integers?

From Dev

Python extension - construct and inspect large integers efficiently

From Dev

Large integers addition error in python 2.7.10

From Dev

Printing string as integers in python 3

From Dev

Multiplying large matrices in Python 3

From Dev

AWK sum of large integers

From Dev

PHP - gmdate() and Large Integers

From Dev

Parallel arithmetic on large integers

From Dev

Python 3 Converting integers to bytes correctly:

From Dev

Duck Typing and acceptance of tuples or integers in Python 3

From Dev

Python extract 3 integers from string

From Dev

TypeError: slice indices must be integers in Python 3

From Dev

SQLite3 and Python 3 - "no such column" error with strings but not integers

From Dev

merge sort with large number of integers

From Dev

The Sum of large Integers using Arrays

From Dev

Python3 Stop division for large floats

From Dev

Python3 How to make a bytes object from a list of integers

From Dev

Count how many individual integers there are in a string, Python 3

From Dev

Python: Does list contain 3 consecutive integers that sum to 7?

From Dev

How to check if sum of 3 integers in list matches another integer? (python)

From Dev

Python3 TypeError: list indices must be integers or slices, not str

From Dev

How to convert nested list strings to integers then sort them in python 3?

From Dev

getting only integers from a list of tuples python 3

From Dev

python 3 function with one argument returning list of integers

From Dev

Python 3 TypeError: string indices must be integers Error

From Java

Measure the efficiency of appending integers to a large dictionary of lists

Related Related

  1. 1

    Handling large integers in python

  2. 2

    Handling large integers in python

  3. 3

    Distinguishing large integers from near integers in python

  4. 4

    How does python represent such large integers?

  5. 5

    Python extension - construct and inspect large integers efficiently

  6. 6

    Large integers addition error in python 2.7.10

  7. 7

    Printing string as integers in python 3

  8. 8

    Multiplying large matrices in Python 3

  9. 9

    AWK sum of large integers

  10. 10

    PHP - gmdate() and Large Integers

  11. 11

    Parallel arithmetic on large integers

  12. 12

    Python 3 Converting integers to bytes correctly:

  13. 13

    Duck Typing and acceptance of tuples or integers in Python 3

  14. 14

    Python extract 3 integers from string

  15. 15

    TypeError: slice indices must be integers in Python 3

  16. 16

    SQLite3 and Python 3 - "no such column" error with strings but not integers

  17. 17

    merge sort with large number of integers

  18. 18

    The Sum of large Integers using Arrays

  19. 19

    Python3 Stop division for large floats

  20. 20

    Python3 How to make a bytes object from a list of integers

  21. 21

    Count how many individual integers there are in a string, Python 3

  22. 22

    Python: Does list contain 3 consecutive integers that sum to 7?

  23. 23

    How to check if sum of 3 integers in list matches another integer? (python)

  24. 24

    Python3 TypeError: list indices must be integers or slices, not str

  25. 25

    How to convert nested list strings to integers then sort them in python 3?

  26. 26

    getting only integers from a list of tuples python 3

  27. 27

    python 3 function with one argument returning list of integers

  28. 28

    Python 3 TypeError: string indices must be integers Error

  29. 29

    Measure the efficiency of appending integers to a large dictionary of lists

HotTag

Archive