False rounding in PYTHON3: round ()

Source: Internet
Author: User

False rounding in PYTHON3: round ()
Creation time: 2017/12/5 17:08
Cn_simo
Label: Python basics, round, rounding

first, this is not a bug!
when using round (), it is found thatcan be found that there are some numbers that are not really rounded!
This is very confusing, check the data found that in the Python2 this is still normal.
  • The definition of round () in Python2 is: a multiple of the negative ndigits in 10 takes the nearest number of numbers back, if it is stored in two times count as close as number, then take away from 0
  • The definition of round () in Python3 is: A multiple of the negative ndigits in 10 takes the nearest number of numbers to return, and if there are two multiples as close as #, take even
 
round () in the Official document: "Reference link"This is not a bug! I still can't figure out why round is going to do this, but there's no doubt it's a pit!second, Accurate rounding method Summary:"reference link"
Method 1: Law 2: Also in Python3 '/' is the ordinary division, divisible by '//'

False rounding in PYTHON3: round ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.