This question already has an answer here: Is floating point math broken? 31 answers I want to save some numbers in a text file. I need to save the numbers in .18f format. The numbers are given as int‘s and must be converted to floats, as shown below, before being stored. unit and factor are […]

- Tags as shown below, before being stored. unit and factor are given (and can be different for other number). factor = 1.0 unit = 10000000 i = 104667 i *= factor, but print(f'{i:.18f}') 0.010466699999999999 I was however hoping there was some way I could "format" myself out of this problem? (I.e. so t, it is probably not correct if the answer is greater than one. And it seems cumbersome. Does anybody have any suggestions on how to simplify, or maybe have a better solution?, This question already has an answer here: Is floating point math broken? 31 answers I want to save some numbers in a text file. I need to s