mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 17:10:24 +08:00
bc12eca461
Prior to this patch the %f formatting of some FP values could be off by up to 1, eg '%.0f' % 123 would return "122" (unix x64). Depending on the FP precision (single vs double) certain numbers would format correctly, but others wolud not. This patch should fix all cases of rounding for %f.
12 lines
272 B
Python
12 lines
272 B
Python
# test float formatting
|
|
|
|
# general rounding
|
|
for val in (116, 1111, 1234, 5010, 11111):
|
|
print('%.0f' % val)
|
|
print('%.1f' % val)
|
|
print('%.3f' % val)
|
|
|
|
# make sure rounding is done at the correct precision
|
|
for prec in range(8):
|
|
print(('%%.%df' % prec) % 6e-5)
|