D
[david]
returns poorly formatted values:
[david]
'[13.300000000000001]'>>>str(13.3) '13.3'
>>>str([13.3])
[david]
'[13.300000000000001]'>>>str(13.3) '13.3'
>>>str([13.3])
returns poorly formatted values:
'[13.300000000000001]'str(13.3) '13.3'
str([13.3])
[david]
returns poorly formatted values:
'[13.300000000000001]'str(13.3) '13.3'
str([13.3])
Bjoern said:returns poorly formatted values:
Please explain.
'[13.300000000000001]'str(13.3) '13.3'
str([13.3])
This is quite a FAQ.
str of a float returns the float, rounded to decimal precision.
str of a list returns a square brackets enclosed enumeration of the
contents (using repr on them). repr of a float returns the float in
full precision.
Regards,
Björn
> contents (using repr on them). repr of a float returns the float in
> full precision.
Leaving aside the question of why str should return repr,
with the repr of their contents. said:13.300000000000001 is not 'the float in full precision':
it is an arbitrary translation of the float.
The idea that 13.3 is a 'rounded' value for the number,
and that 13.300000000000001 is not a 'rounded' value of
the number, is a common error of intuitive mathematics.
I hope that when you say that this is a FAQ, you don't
mean that the community has solidified on this naive
interpretation :~)
I'm intrigued how /you/'d explain this, please do explain.
I believe the claim is that using the full 17 digits ensures the round-
tripping works even if you serialise and deserialise on different
systems, so perhaps we all pay a cost in our interactive sessions for
something which should really be buried deep in IPC code.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.