On 18/12/2022 01.39, Peter J. Holzer wrote:
On 2022-12-17 12:51:17 +0100, Paul St George wrote:
I have a large/long array of numbers in an external file. The numbers
look like this:
-64550.727
-64511.489
-64393.637
[...]
When I bring the numbers into my code, they are Strings. To use the
numbers in my code, I want to change the Strings to Float type because
the code will not work with Strings but I do not want to change the
numbers in any other way.
s = "-64550.727"
f = float(s)
f
-64550.727
type(f)
<class 'float'>
(Contrary to the other people posting in this thread I don't think float
is the wrong type for the job. It might be, but you haven't given enough
details to tell whether the inevitable rounding error matters or not. In
my experience in almost all cases where people think it matters it
really doesn't.)
Agreed: (ultimately) insufficient information-provided.
(but that probably doesn't matter either - as the OP seems to have come
to a decision)
Agreed: probably doesn't matter.
'The world' agrees with both, having decided that Numerical Analysis is
no-longer a necessary ComSc study.
In the ?good, old, days Numerical Analysis included contemplation of the
difficulties and differences between "precision" and "accuracy". Thus,
the highly accurate calculation of less-than precise numbers - or was it
precise values subject to less than accurate computation?
(rhetorical!)
Sort of like giving highly-accurate answers to a less-than precise
(complete) question, by presuming can ignore the latter.
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list