In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly talks about "matters needing attention in numerical calculation in PHP". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "points for attention in numerical calculation in PHP".
One: rounded
1.round-rounding floating point numbers
Float round (float $val [, int $precision])
2:floor-rounding (rounding down)
Float floor (float $value)
3.ceil-one-in rounding (rounding up)
Float ceil (float $value)
Pit points: when the value is an integer, for example, 11, then floor (11) = 10, ceil (11) = 12; the problem is obvious, so pay special attention to this when calculating.
Solution: floor (11 + 0.01)
Two: multiplication and division of integers and decimals
This is true in the php world. If you use the +-* / of php to calculate floating-point numbers, you may encounter some incorrect results, such as echo intval (0.58-100). It prints 57 instead of 58, which is actually a bug in which floating-point numbers cannot be accurately represented by the underlying binary of the computer, which is cross-language, and I have the same problem with python. So basically most languages provide accurate computing class libraries or function libraries, such as php has a BC high-precision function library
The solution is to change the integer into a floating-point type 3.5x (float) 100 = 350.
Three: the weirdness of floating point numbers
Pothole: 8.50-8 = 0.500000001 actually the reason is similar to 2.
Solution: round () the result to improve the accuracy.
At this point, I believe you have a deeper understanding of the "matters needing attention in numerical calculation in PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.