Print Currency Number Format in PHP(在 PHP 中打印货币数字格式)
问题描述
我有一些价格值要显示在我的页面中.
I have some price values to display in my page.
我正在编写一个函数,它采用浮动价格并返回带有货币代码的格式化货币 val..
I am writing a function which takes the float price and returns the formatted currency val with currency code too..
例如,fnPrice(1001.01) 应该打印 $ 1,000.01
推荐答案
最简单的答案是number_format().
The easiest answer is number_format().
echo "$ ".number_format($value, 2);
如果您希望您的应用程序能够使用多种货币和支持区域设置的格式(例如,对于我们一些欧洲人来说是 1.000,00),它会变得有点复杂.
If you want your application to be able to work with multiple currencies and locale-aware formatting (1.000,00 for some of us Europeans for example), it becomes a bit more complex.
有 money_format() 但它不适用于 Windows并且依赖于setlocale(),在我看来这很垃圾,因为它需要在服务器端安装(任意命名的)语言环境包.
There is money_format() but it doesn't work on Windows and relies on setlocale(), which is rubbish in my opinion, because it requires the installation of (arbitrarily named) locale packages on server side.
如果您想认真国际化您的应用程序,请考虑使用完整的国际化库,例如 Zend Framework 的 Zend_Locale 和 Zend_Currency.
If you want to seriously internationalize your application, consider using a full-blown internationalization library like Zend Framework's Zend_Locale and Zend_Currency.
这篇关于在 PHP 中打印货币数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PHP 中打印货币数字格式
				
        
 
            
        - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - Laravel 仓库 2022-01-01
 - PHP Count 布尔数组中真值的数量 2021-01-01
 - 带有通配符的 Laravel 验证器 2021-01-01
 - Mod使用GET变量将子域重写为PHP 2021-01-01
 - 如何定位 php.ini 文件 (xampp) 2022-01-01
 - 从 PHP 中的输入表单获取日期 2022-01-01
 - 没有作曲家的 PSR4 自动加载 2022-01-01
 - 正确分离 PHP 中的逻辑/样式 2021-01-01
 - SoapClient 设置自定义 HTTP Header 2021-01-01
 
				
				
				
				