Home > Article > Backend Development > What are the methods of rounding down in Python?
In python, you can use the following method to round down:
//
, which truncates the result to the nearest integer less than or equal to the original value. x = 7.8 y = x // 1 print(y)# 输出: 7
math.floor()
function, which returns the largest integer not greater than the input parameter. import math x = 7.8 y = math.floor(x) print(y)# 输出: 7
numpy.floor()
function, which returns the largest integer not larger than the input argument. import numpy as np x = 7.8 y = np.floor(x) print(y)# 输出: 7.0
These methods can be selected and used according to specific needs.
The above is the detailed content of What are the methods of rounding down in Python?. For more information, please follow other related articles on the PHP Chinese website!