Reply to Re: clean currency input

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация