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
There are several ways to intercept floating-point types in PHP:
1, float round (float $val [, int $precision]) Returns the result of rounding Val based on the specified precision precision (number of digits after decimal decimal point). Precision
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
There are several ways to intercept floating-point types in PHP. Need friends can come to the reference, I hope to help you
There are several ways to intercept floating-point types in PHP:
1, float round (float $val [, int $precision]) Returns the
Java float addition and subtraction accuracy can be converted to bigdecimal when this field is obtained, while bigdecimal can be set. Float M = 12.22f; float c = 1.22f; bigdecimal b1 = new bigdecimal (float. tostring (m); bigdecimal b2 = new
Decimal Example:
PHP retains two decimal places and rounded up
Copy Code code as follows:
$n = 0.1265489;
Echo sprintf ("%.2f", $n); 0.13
You can see we used the sprintf function to format the $n%.2f is the target format,
In the project, the float type is used to define some columns, such as price, but many problems are found.1. When the number of bits on the value is greater than 6, the float type is converted to the varchar type, which is displayed in the
PHP rounding, rounding, round function Use example, rounding round
Decimal Example:
PHP reserved two decimal places and rounded
Copy the Code code as follows:$n = 0.1265489;Echo sprintf ("%.2f", $n); 0.13
As you can see, we used the sprintf
During the development process, which of the following statements will you use for data processing and rounding? Xiao Tao will introduce the PHP integer functions including ceil, floor, round, and intval. The following describes in detail: 1. ceil &
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.