Alibabacloud.com offers a wide variety of articles about python round to 2 decimal places, easily find your python round to 2 decimal places information here online.
I ran into a problem today when I wrote the program. about how to control floating-point numbers only two digits after the decimal point, the normal idea is to use the round function, such as round (A, 2), but in the face of the following problems
The Python version also affects the results, and python2 the x round to the nearest multiple from 0, such as round (0.5) =1, round (-0.5) =-1;
Python3 rounds x to the nearest number of even multiples, such as round (0.5) =0, round (1.5) =2.0, round (
Python built-in functions (55) -- round, python built-in 55 round
English document:
round(
Number[,
Ndigits])
Return the floating point value
NumberRounded
NdigitsDigits after the decimal point. If
NdigitsIs omitted, it
Https://www.cnblogs.com/herbert/p/3402245.htmlBasisThe floating-point number is represented by the machine's double-precision (a-bit) of the floating-point number. provides approximately 17 bits of precision and ranges from 308 to 308 of the
In python, round (x, [n]) uses round (x, [n]) to rounding n to retain the number of fractional parts
1. when n is not entered, the default value is 0, that is, the fractional part is not retained.A. When the decimal part is only 0.5, if the integer
BasisThe floating-point number is represented by the machine's double-precision (a-bit) of the floating-point number. provides approximately 17 bits of precision and ranges from 308 to 308 of the exponent. Same as the double type in the C language.
It is the result of Lua's computation. We can see that the computation result is very accurate. It is the calculation result of Python3. We can see that the calculation result is inaccurate: the decimal computation in JavaScript is also inaccurate.
English documents:
round
(number[, ndigits])
Return The floating point value
number rounded to
ndigits digits after the decimal point. If
ndigits is omitted, it returns the
Detailed explanation of the basic mathematical computing usage in Python programming, detailed explanation of python programming mathematics
QuantityIn Python, the provisions on logarithm are relatively simple and can be understood basically at the
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.