QUERY · ISSUE
f presentation type is not rounding
needs-info
In MicroPython (tested with version 1.9.3) the f presentation type (as in "{:.0f}".format(x)) is not rounding floating point numbers as CPython (tested with 3.7.2) does. Actually I'm not sure what it really does. It is not rounding, not flooring and not truncating as the following examples show:
print("{:.0f}".format(100.0))
CPython: >>> 100
MicroPython: >>> 100
print("{:.0f}".format(100.9))
CPython: >>> 101
MicroPython: >>> 100
print("{:.0f}".format(101.0))
CPython: >>> 101
MicroPython: >>> 100
print("{:.0f}".format(99.5))
CPython: >>> 100
MicroPython: >>> 99
print("{:.0f}".format(99.6))
CPython: >>> 100
MicroPython: >>> 100
CANDIDATE · ISSUE
f-string thousands separator doesn't work with floats
bugpy-core
On v1.19.1, f-string thousands separator doesn't work with floats. Tested on both unix and rp2040:
Demo code:
foo_int = 123456
foo_float = 1234.56789
print(f"{foo_int:,} {foo_float:,}")
CPython (correct):
123,456 1,234.56789
MicroPython (incorrect):
123,456 1234.57