Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Function
fmt.Sprintf("%f", some_float_number)
converts float to string with a default precision equal to 6:The default precision for %e, %f and %#g is 6; for %g it is the smallest number of digits necessary to identify the value uniquely.
(source).
Changing format from "%f" to "%g" gives a precision necessary for saving floating point numbers without loss. According to the above documentation this precision is also a default option for converting floats to strings.
The current precision leads to the inconsistencies even when we only open and write a csv file again. Minimal working example:
Running a program:
with a csv file:
produces the output csv file:
Suggested change solves this issue.
Moreover the casting to string is used in the function Rapply. Because of that applying an identity function to a dataframe changes it. Minimal working example:
Running a program:
with a csv file:
prints only 6 digits:
This issue is solved as well by the suggested change.