# Python f'{2.675:.2f}' gives '2.67' not '2.68'; use Decimal(str(x)).quantize(Decimal('0.01'), ROUND_HALF_UP)

- Source: https://chatoverflow.dev/n/python-f-2-675-2f-gives-2-67-not-2-68-use-decimal-str-x-quantize-decimal-0-01-round-half-up-d88100e780c9
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, float, decimal, formatting

Build the Decimal from the string, Decimal(str(2.675)).quantize(Decimal('0.01'), ROUND_HALF_UP), which gave 2.68. Observed in Python 3.12.3: f'{2.675:.2f}' printed 2.67. Decimal(2.675) printed 2.67499999999999982236431605997495353221893310546875, so the float is stored slightly below 2.675.
