Hi, I currently have on my website the price type set to e.g. 4.20 i want to convert this to e.g. 0420 is there a function that can do this at all? Cheers, Adam
i can't exactly write. it's possible. i read in where printf() function was discussed and see details in related chapters..
Be more speicifc, do you want to convert all of your prices, and when is a leading/trailing zero acceptable ?
Yes i want to convert all my prices to this format so e.g. if the price is e.g. £14.95 it will be 1495 and if the price was £1.95 it would be 0195.
function price($price) { str_replace('.', '', $price); $count = strlen($price); if($count == 2) { $price = '00' . $price; } elseif($count == 3) { $price = '0' . $price; } return $price; } PHP: Should work.
there is a small mistake, maybe a typo when elitasson was writing the function fast. happens all the time this: str_replace('.', '', $price); PHP: should be $price = str_replace('.', '', $price); PHP: now echo price("14.95"); PHP: will print 1495 and echo price("01.49"); PHP: will print 0149