How do I retain the zero decimal point?

Source: Internet
Author: User
How do I retain the zero decimal point? Suppose there is a string $ a = '8 RMB '; $ B = '8. 3'; how to change it to $ c = '8. 0 RMB '?


Reply to discussion (solution)

$ B = '8. 3'; echo number_format (floor ($ B), 1). 'meta ';

$ B = '8. 3'; echo number_format (floor ($ B), 1). 'meta ';



What about $?

$ A = '8 RMB '; echo preg_replace_callback (' # (\ d +) RMB # ', create_function (' $ M ', 'return number_format (floor ($ m [1]), 1 ). "Yuan"; '), $ );

You should save and format the numbers separately and splice them with "yuan" or other characters.

$ A = '8 yuan '; $ B = '8. 3'; echo intval ($ ). '. 0'; echo intval ($ B ). '. 0 ';

$c = sprintf('%.1f',intval($a));

$ A = 8.3;

// First
$ C1 = number_format (floor ($ a), 1 );
Echo $ c1 ."
";

// Type 2
$ C2 = sprintf ("%. 1f", floor ($ ));
Echo $ c2 ."
";

$ C3 = printf ("%. 1f", floor ($ ));
Echo $ c3 ."
";

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.