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 ."
";