Skip to content

Converting floats to string has surprising results

If I parse "42.0" into a Float, then call .to_string_radix(10, None), I expected to see 42.0 but instead got 4.2000000000000000e1.

The number of zeroes is not too surprising, but the fact that 42 was converted to 4.2e1 is rather strange. Is there something I am doing wrong, or another way I can approach this so that I can print the expected numbers?