In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the methods of php float not rounding to intercept floating-point strings". In daily operations, I believe many people have doubts about the methods of php float not rounding and intercepting floating-point strings. The editor consulted all kinds of data and sorted out simple and useful operation methods. I hope it will be helpful to answer the doubts of "php float does not round off to intercept floating-point strings." Next, please follow the editor to study!
There are roughly 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 (the number of digits after the decimal point). Precision can also be negative or zero (default).
Echo round (4.3) / 4
2. String sprintf (string $format [, mixed $args [, mixed $...]]) returns a string of formatted data
The copy code is as follows:
$axim 12.338938438
Echo sprintf ("% .5f", $a) / / result: 12.33894
$axim 12.3312356
Echo sprintf (".5f", $a); / / 12.33124
Echo sprintf ("% f", $a); / / 331236 default 6 decimal places
3. String number_format (float $number, int $decimals, string $dec_point, string $thousands_sep)
The copy code is as follows:
$number = 1234.5678
$english_format_number = number_format ($number, 2,'.'')
Echo $english_format_number; / / 1234.57
All of the above are automatically rounded, sometimes the demand does not need to be rounded, how to do, did not think of a good way, who knows can tell.
I wrote a trouble-point function and recorded it.
The copy code is as follows:
Function getFloatValue ($fjcjinlen)
{
$tmpInt=intval ($f)
$tmpDecimal=$f-$tmpInt
$str= "$tmpDecimal"
$subStr=strstr ($str,'.')
If (strlen ($subStr)
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.