How to make up for less than 10 digits in php
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
