In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of php supplement 0 what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you will have some gains after reading this php supplement 0 method, let's take a look at it.
In PHP, there are functions to achieve complement 0, which are: 1, "str_pad ()" function, syntax is "str_pad (numerical value, length after filling 0," 0 ", position of complement 0); 2, sprintf () function, syntax is" sprintf (format, numeric) ".
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.
Does php have a function that complements 0?
There are two functions in php-- at least two-- I don't know if there are any other functions that can achieve digital zero padding. Str_pad () and sprintf () are detailed as follows.
Str_pad
As the name implies, this function is for strings, and this can fill any other string for the specified string.
For example: str_pad (string with padding, length after padding, padding string, filling position)
The length after filling must be a positive integer, and there are three options for filling position.
Left: STR_PAD_LEFT
Right: STR_PAD_RIGHT
Both ends: STR_PAD_BOTH
For example:
Echo str_pad (1Jing 8, "0", STR_PAD_LEFT)
Results: 00000001
Echo str_pad (1Jing 8, "0", STR_PAD_RIGHT)
Results: 10000000
Echo str_pad (1Jing 8, "0", STR_PAD_BOTH)
Results: 00010000
One detail worth noting in the above example is that if the number of digits filled is an odd number, for example, in example 3, seven zeros are filled, the right side takes precedence.
Let's take a look at another method of zero filling, sprintf.
But let's not say so much, because it is so flexible that I can hardly use it, but it is very convenient to use zeros on the left (or after the decimal point).
Let's first look at the zero filling on the left.
Echo sprintf ("d", 1)
Let's start with the meaning of d, format the following parameters with a five-digit number, and fill in zeros if there are less than five digits.
The running result is 00005.
Let's take a look at the zero after the decimal point.
Echo sprintf (".3f", 1)
.3f means that the following parameters are formatted with at least three places after the decimal point, less than three places before the decimal point, and less than one place before the decimal point.
The running result is: 1.000
This is the end of the article on "what are the methods of php 0". Thank you for your reading! I believe you all have a certain understanding of the knowledge of "what are the methods of php 0". If you want to learn more knowledge, you are welcome to follow the industry information channel.
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.