[Python] Mostrare decimali solo se diversi da 0.

Marco Beri marcoberi a gmail.com
Gio 3 Dic 2020 18:33:08 CET


On Thu, 3 Dec 2020 at 18:26, Ernesto Arbitrio <ernesto.arbitrio a gmail.com>
wrote:

> potresti usare qualcosa del tipo:
> print("{0}".format(str(round(x, 1) if x % 1 else int(x)))
>

Oppure:

>>> f"{6:g}"
'6'
>>> f"{6.0:g}"
'6'
>>> f"{6.5:g}"
'6.5'

Ciao.
Marco.
-------------- parte successiva --------------
Un allegato HTML รจ stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20201203/def23209/attachment.html>


Maggiori informazioni sulla lista Python