Python - How to keep decimal places from list item to variable?

Asked

Viewed 141 times

2

I am using Python inside the SPSS to read some values within a dataset. These values are stored in a list. I am using 15 decimal places and in the list the values appear with 15 houses. However when I copy the value to a variable this stores with up to 12 houses. Ex. list = [0,123456789101112, 0,987654321012345]

x = Lite[0]

When use x is loaded type 0,123456789.

This happens even if I use: x = float(list[0]). Python version is 2.7.6 and SPSS 23.

  • Yes, floating points have display and value problems. There is not much to do when it comes to numbers of this kind.

  • 1

    I recommend reading this question: https://answall.com/q/219211/64969 and watching this video: https://youtu.be/pQs_wx8eoQ8

1 answer

2

I tested here with Python 2.7 and 3.6 and the result was the same

>>> lista = [0.123456789101112, 0.987654321012345]
>>> a=lista[0]
>>> lista[0]
0.123456789101112
>>> a
0.123456789101112

In other words, printed the value

Browser other questions tagged

You are not signed in. Login or sign up in order to post.