Method 1: round(X, N)
This method is not strictly valid. When the number of decimal places in X is n Method 2: print('%.Nf'%X) or print("%.Nf"%X) Note that this method has two There are "%" and no ",". Method 3: print(format(X, '.Nf') or print(format(X, ".Nf") Pay attention to this method There is no "%", but there is ",". 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!