sprintf and printf two functions in PHP usage tips

Source: Internet
Author: User

"Go from e-mentor Network " Here is an example: rounding retains two digits after the decimal point

650) this.width=650; "src=" Http://183.61.143.148/group1/M00/01/FA/tz2PlFQH_1_QKdbuAAAfVXuKLV4952.png "/>

explain the meaning of the following%0.2f:

% represents the starting character
0 indicates that the empty space is filled with 0
2 means that the decimal point must be two bits
Span style= "Line-height:2;font-size:16px;font-family:simsun;" > F to convert to floating point number


Convert characters
% printed percent symbol, not converted.
b integer turns into binary.
The c integer is converted to the corresponding ASCII character.
D integers are turned into 10.
The F-Times precision number is converted to floating point numbers.
o integers are turned into octal.
The s integer is converted into a string.
The x integer is converted to lowercase 16 rounding.
X integers are converted to uppercase 16 rounding.

the difference between printf and sprintf

1. printf function:

int printf (string format [, mixed args [, mixed ...])

produces output according to format, which are described in the documentation for SPRINTF ().

Returns The length of the outputted string.

the text is formatted for later output, such as:

650) this.width=650; "src=" Http://183.61.143.148/group1/M00/01/FA/tz2PlFQH_3iAyTr3AAAL4QtsyQA162.png "/>

2. sprintf function:
string sprintf (string format [, mixed args [, mixed ...])

Returns A string produced according to the formatting string format.

similar to printf, but does not print, but returns formatted text, the rest is the same as printf.

3. Print function:

is a function that returns a value that can have only one parameter.

int Print (string arg)

Outputs Arg. Returns 1, always.

more Programming Language Tutorials Knowledge Please login e mentor net.

This article is from the "Add Language" blog, please make sure to keep this source http://yuguotianqing.blog.51cto.com/9292883/1549396

sprintf and printf two functions in PHP usage tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.