Home >Backend Development >Python Tutorial >What are the methods of rounding down in Python?

What are the methods of rounding down in Python?

WBOY
WBOYforward
2024-03-01 17:55:021648browse

What are the methods of rounding down in Python?

In python, you can use the following method to round down:

  1. Use the integer division operator //, 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
  1. Use the 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
  1. Use the 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!

Statement:
This article is reproduced at:lsjlt.com. If there is any infringement, please contact admin@php.cn delete