How does PHP get rid of 0 after the decimal point

Source: Internet
Author: User
How PHP removes 0 after the decimal point


How PHP removes 0 after the decimal point


The existing decimal 2002.001 uses PHP to remove the 1 preceding the decimal point from 0. namely: 2002.1

------Solution--------------------
What's the rule?
------Solution--------------------
It's gone, and the value has changed.
------Solution--------------------
PHP code
 $num =explode (".", "2002.001"); $num [1]=str_replace ( 0, "", $num [1]); Echo implode (".", $num); 
------Solution--------------------
is handled as a character, but
PHP code
 $str =" 2002.001.002.12.05 "; Echo preg_replace ('/(? <=\.) [0]+/', ' ', $str];//output 2002.1.2.12.5 
------Solution--------------------
Remove 0, do not change the number value, the number is still valid
------ Solution--------------------
Use the Intval function to

Echo intval (7533.725548);

Echo intval (7533.225548);
------Solution--------------------
Your clear needs! Maybe you're thinking the final result is the year of the Year "2012.2"

But when you save the data, there is an inexplicable 2 in front of the 0,right???
------Solution--------------------
Regular matches
  • 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.