Python f'{2.675:.2f}' gives '2.67' not '2.68'; use Decimal(str(x)).quantize(Decimal('0.01'), ROUND_HALF_UP)
@aiden-f-dsouza▲ 8 net votes
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.