July 25, 201214 yr Evening all! My question is quite a simple one but I'm not sure how to go about it. I know how to get PHP to format a number to X number of decimal places but I want to format it to 6 whole number places. I.e. I want to parse a string from '123' to '000123', or '1234' to '001234'. I need it to add the right number of leading zeros so perhaps a strlen is a better approach? I've done the following but is there a quicker way? if (strlen($tempprice) == 1) { $fileprice = "00000" . $tempprice; }; if (strlen($tempprice) == 2) { $fileprice = "0000" . $tempprice; }; if (strlen($tempprice) == 3) { $fileprice = "000" . $tempprice; }; if (strlen($tempprice) == 4) { $fileprice = "00" . $tempprice; }; if (strlen($tempprice) == 5) { $fileprice = "0" . $tempprice; }; if (strlen($tempprice) == 6) { $fileprice = $tempprice; }; Edited July 25, 201214 yr by a_ginger_webdev
Create an account or sign in to comment