Home >Backend Development >Python Tutorial >How to output specified decimal places in python

How to output specified decimal places in python

尚
Original
2019-07-03 14:43:1114019browse

How to output specified decimal places in python

Method 1: round(X, N)

This method is not strictly valid. When the number of decimal places in X is n

How to output specified decimal places in python

Method 2: print('%.Nf'%X) or print("%.Nf"%X)

Note that this method has two There are "%" and no ",".

How to output specified decimal places in python

Method 3: print(format(X, '.Nf') or print(format(X, ".Nf")

Pay attention to this method There is no "%", but there is ",".

How to output specified decimal places in python

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to output specified decimal places in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn