How does php remove 0 after the decimal point?

Source: Internet
Author: User
How does php remove the 0php after the decimal point? How does PHP remove the 0php after the decimal point? 2002.001 how does php remove the zero before the decimal point. That is: 2002.1 ------ solution ------------------ what is the rule? ------ Solution ------------------ removed, and the value also changed ------ solution -------------------- PHP php how to remove 0 after the decimal point


How does php remove 0 after the decimal point?


How to remove the zero before the first decimal point in PHP with a decimal point of 2002.001. That is, 2002.1

------ Solution --------------------
What's the rule?
------ Solution --------------------
Removed, and the value has changed.
------ Solution --------------------
PHP code
$ Num = explode (". "," 2002.001 "); $ num [1] = str_replace (0," ", $ num [1]); echo implode (". ", $ num );
------ Solution --------------------
Can be processed as characters.
PHP code
$ Str = "2002.001.002.12.05"; echo preg_replace ('/(? <= \.) [0] +/', '', $ str); // output 2002.1.2.12.5
------ Solution --------------------
If the value of 0 is removed, the numeric value will not be changed. is the number still valid?
------ Solution --------------------
Use the intval function.

Echo intval (7533.725548 );

Echo intval (7533.225548 );
------ Solution --------------------
Your need is clear! Maybe the final result you want is the year and month (2012.2]

But when you store data, there are 0, right ???
------ Solution --------------------
Regular Expression Matching

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.