|
Posted by Janwillem Borleffs on 10/13/26 11:36
windandwaves wrote:
> I am sure that this is probably the clumsiest way ever to do this. How can
> I improve this function?
>
function format_currency($n) {
$n = preg_replace('/[^\d.]+/', '', $n);
return sprintf('%01.2f', $n);
}
As you will notice, I have also modified the function name as "is_currency"
suggests that it returns a boolean rather then a formatted number.
For currency formatting you can apply the number_format() function, in case
you've missed it.
JW
Navigation:
[Reply to this message]
|