4

I have values like 656364.53 which has to be read from a text file. From my programming experience, I have learnt that is value takes the double data type, to be retained as a proper value.

In python however, it seems that there is only float or the single - precision value. Therefore as per my experience, these values get changed on reading.

How do I get double precision values in python.

2
  • 1
    Try the Decimal module perhaps. Commented Nov 3, 2013 at 11:30
  • Jason Sperske below is giving the correct answer. If you need exact control over the datatype used for your numbers, the numpy module is very useful. This supports floating point and integer numbers with a range of precision. (though the Decimal module might be better for some applications) Commented Nov 3, 2013 at 11:34

2 Answers 2

5

According to the documentation:

Floating point numbers are usually implemented using double in C; information about the precision and internal representation of floating point numbers for the machine on which your program is running is available in sys.float_info.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are going to perform mathematical operations on this data and accuracy is an issue I suggest you'll look at the decimal data type we had some issues with floating point error.

Decimal “is based on a floating-point model which was designed with people in mind, and necessarily has a paramount guiding principle – computers must provide an arithmetic that works in the same way as the arithmetic that people learn at school.”

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.