Answer the question
In order to leave comments, you need to log in
Python: format str float - how to hide the fractional part if it is zero?
Python3.4.
It is necessary to form a line with a price.
If the fractional part of the price is 0, then do not display it (the fractional part).
Answer the question
In order to leave comments, you need to log in
>> from decimal import Decimal
>>> quantize = Decimal('.01')
>>> print(Decimal(123.456).quantize(quantize).normalize())
123.46
>>> print(Decimal(123.00).quantize(quantize).normalize())
123
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question