PHP 5.3.0 NumberFormatter replacement
In PHP 开发者_如何学Go5.3.0+ (on my local server) I have intl
library installed. I use NumberFormatter
class. I need it to convert floats to various formats (percentage, decimal, currency, etc.)
But on my real server I have PHP 5.2.14 installed. And I can't update it (I'm not the owner).
Do you know (or use) some classes for formatting numbers? Can you recommend something? I need something like NSNumberFormatter
in iOS, but on PHP.
How about using number_format? It is fairly limited compared to NumberFormatter, but might be enough for your needs.
Another option that might be more suitable for currency formatting is money_format, but that requires that all the locales are properly configured on the servers.
Yet another option is Zend_Currency, which offers very powerful currency formatting in various locales regardless of the server configuration. Zend Framework supports PHP 5.2.x.
精彩评论