We can look how CPython does it, but one algorithm is to take the above strings, try to remove last 4 digits, and then check if there is a sequence of 4 or more 0s or 9s. If so, then remove all 0s and print the rest, so 324.30000000000001137 becomes 324.3. If it is 9s, then remove all 9s, then add one in the last place, so 56.43099999999999739 -> 56.4309999999999 -> 56.430 -> 56.431.
Currently code like this:
Can print like this:
But it should print like this:
We can look how CPython does it, but one algorithm is to take the above strings, try to remove last 4 digits, and then check if there is a sequence of 4 or more 0s or 9s. If so, then remove all 0s and print the rest, so
324.30000000000001137
becomes324.3
. If it is 9s, then remove all 9s, then add one in the last place, so56.43099999999999739
->56.4309999999999
->56.430
->56.431
.