Php decimal places

Source: Internet
Author: User
Php takes a decimal place and waits for $ str = 35.5454 online. how can we get 35.5?, PHPcode $ result = round (35.5454, 1);, $ str = 35.5454; $ str = number_format ($ str, 1); & nbsp; echo $ php takes a decimal point, online, etc.
$ Str = 35.5454;

Select 35.5.
How to implement it,

------ Solution --------------------
PHP code
$ Result = round (35.5454, 1 );
------ Solution --------------------
$ Str = 35.5454;
$ Str = number_format ($ str, 1 );
Echo $ str;
------ Solution --------------------
Discussion

$ Str = 35.5454;
$ Str = number_format ($ str, 1 );
Echo $ str;

------ Solution --------------------
PHP code
$ Str = 35.5454; $ num = number_format ($ str, 1)
------ Solution --------------------
$ Xxx = sprintf ('%. 1f', $ xxx );
------ Solution --------------------
$ Result = round (35.5454, 1 );
------ Solution --------------------
Close the post to score.
Is it online ????
------ Solution --------------------
Sprintf ('% 0.1f', $ str );
------ Solution --------------------
Float!
------ Solution --------------------
Round (35.5454, 1 );
------ Solution --------------------
Round (3.14159, 1 );

Number_format (3.14159265, 1, '.', ''); // The result is better. if the ending number is 0, the value of 0 is automatically added.
------ Solution --------------------
Discussion
Round (3.14159, 1 );

Number_format (3.14159265, 1, '.', ''); // The result is better. if the ending number is 0, the value of 0 is automatically added.

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.