Wednesday 20 July 2011

PHP float to money and back again

So I've a need of converting a float from a MySQL query into a currency value so it'll print nicely. THis works a treat:

$dosh = number_format($float, 2);

But bringing it back into the table means I searched and found this way:

$float = (float) str_replace(',', '', $dosh);

Seemed to work a treat TBH ;-)

No comments:

Post a Comment