Completion method: 1. Use the "str_pad(numeric value, 10, "0", STR_PAD_RIGHT)" statement, and use zeros to supplement less than 10 digits; 2. Use "sprintf(" f", numerical variable)* pow(10,(10-strlen(numeric variable)))" statement, any less than 10 digits are padded with zeros.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php implementation is less than 10 Method of padding the digits with 0
1. Use the str_pad() function
str_pad() function to fill the string to the new length
Use the str_pad() function to return 10 digits, and add zeros if it is less than 10 digits.
<?php echo str_pad(12853,10,"0",STR_PAD_RIGHT)."<br>"; echo str_pad(1252,10,"0",STR_PAD_RIGHT)."<br>"; echo str_pad(1283365,10,"0",STR_PAD_RIGHT)."<br>"; ?>
Description: Possible values for the fourth parameter of this function:
STR_PAD_BOTH
- Fill Both sides of the string. If it's not an even number, the right side gets extra padding.STR_PAD_LEFT
- pads the left side of the string.STR_PAD_RIGHT
- Pads the right side of the string. This is the default.
2. Use the sprintf() function
Use the sprintf() function to format the value and convert it to A floating point number that specifies the number of decimal places.
Then multiply the decimal by (10 to the nth power) to convert it to 10 digits
<?php $c=12345; echo sprintf("%10f",$c)*pow(10,(10-strlen($c)))."<br>"; $c=123; echo sprintf("%10f",$c)*pow(10,(10-strlen($c)))."<br>"; $c=123366; echo sprintf("%10f",$c)*pow(10,(10-strlen($c)))."<br>"; $c=1234452; echo sprintf("%10f",$c)*pow(10,(10-strlen($c)))."<br>"; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to make up for less than 10 digits in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
