在PHP中打印货币数字格式 [英] Print Currency Number Format in PHP

查看:338
本文介绍了在PHP中打印货币数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些价格值显示在我的网页。

我正在写一个函数,它采用浮动价格,并返回格式化货币val与货币代码。 。
$ b

例如, fnPrice(1001.01)应该打印 $ 1,000.01

解决方案

最简单的答案是 number_format()

  echo$.number_format($ value,2); 

如果您希望您的应用程序能够使用多种货币和区域设置的格式( 1.000,00 对于我们中的一些欧洲人来说),它变得有点复杂。



money_format() ,但在Windows上不起作用,在 setlocale()上,这在我看来是垃圾,因为它需要在服务器端安装(任意命名的)区域设置包。



如果你想认真国际化你的应用程序,可以考虑使用一个全面的国际化库,比如Zend Framework的 Zend_Locale Zend_Currency


I have some price values to display in my page.

I am writing a function which takes the float price and returns the formatted currency val with currency code too..

For example, fnPrice(1001.01) should print $ 1,000.01

解决方案

The easiest answer is number_format().

echo "$ ".number_format($value, 2);

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.

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.

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中打印货币数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆