Answer the question
In order to leave comments, you need to log in
Floating point error result value correction?
I receive via websocket (I don’t cook data) sometimes like this, for example, victims of a floating point
feature 0.9192899999999999
3.2340000000000001
In order not to set the rounding vector and bit depth for each value, can you suggest a general rounding method with minimal overhead?
Obviously the values should come out
0.91929
3.234
python float. although string is also possible, it’s still possible to shoot further on the websocket
UPD:
If the task is difficult to implement or simply incomprehensible due to the tongue-tied presentation, please help with the regular expression to cut off all nines (or zeros) on the right, along with something to the right, if there are (nines or zeros) more than five in a row.
Thank you.
Answer the question
In order to leave comments, you need to log in
The solution from the comment from shurshur is simple to disgrace. Clear and working. What feature makes it unsuitable for solving the problem?
>>>round(1.1234567899999999, 10)
1.12345679
>>> round(3.234000000000001, 10)
3.234
>>> round(0.9192899999999999, 10)
0.91929
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question