In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the example analysis of true division, truncation division and rounding comparison in Python3 division, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.
Comparison of true division, truncation division and lower rounding of Python3 division
A partner left a message to see the comparison of different kinds of division rounding in Python3! Coming! It looks over here!
In Python3, division in mathematical operations is divided into two types, namely, "true division", that is, the result of division of any type will retain the decimal point, which is consistent with the result of our actual mathematical operation, while "truncation division" is that the result of division of any type will omit the decimal part of the result, leaving the smallest integer part that can be divisible.
The following are the basic forms of two division:
# true division X / Y # truncation division X / Y
True division
X = 8Y = 2Z = 3print (X / Y) print (X / Z)
Example result:
4.02.6666666666666665
The result of true division shows that the division result returns a floating-point result regardless of the type of Operand.
Truncation division
X = 8Y = 2Z = 3s =-8print (X / Y) print (X / Z) print (S / Y) print (S / Z)
Example result:
42-4-3
We can see from the example that truncated division does not really directly remove the number after the decimal point, but is similar to the floor method in the module math, that is, rounding down, and the negative value is rounded in the same way.
Import mathmath.floor (2.0) math.floor (2.6666666666666665) math.floor (- 2.0) math.floor (- 2.6666666666666665)
Example result:
22-2-3
The ceil method in the same module math can realize the up-rounding of floating point numbers.
Import mathprint (math.ceil (2.0)) print (math.ceil (2.666666666666666665) print (math.ceil (- 2.6666666666666665) print (math.ceil (- 2.6666666666666665)) 23-2-2 example analysis of true division, truncated division and rounding down in Python3 division is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.