是否有PHP函数可以将货币金额格式化为会计格式? [英] Is there a PHP function to format a currency amount in accounting format?

查看:179
本文介绍了是否有PHP函数可以将货币金额格式化为会计格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用PHP编写报告,有时不得不显示负货币金额。所述货币量像 -44.00一样存储在数据库中。理想情况下,该数字将在报告上输出为($ 44.00)。

I'm currently writing a report in PHP that occasionally has to display negative currency amounts. Said currency amounts are stored in the database like "-44.00". Ideally this number would be output as "($44.00)" on the report.

我知道我可以编写一些半复杂函数来检测该数字是否为负,并手动进行插入括号,但是我想知道在重新发明轮子之前是否有一些方便的PHP函数可以为我完成此操作。我到处搜寻,却没有发现任何可以完成这项任务的东西。我了解money_format,但看不到任何处理负数/括号的方法。请记住,无论数字是负数还是正数,代码都必须起作用。

I know I can write some semi-complicated function to detect whether the number is negative and manually insert the parenthesis, but I was wondering if there was some handy PHP function that can do this for me before I re-invent the wheel. I've searched around and have not found anything that seems to do this exact task. I know about money_format, but I don't see any way to do the negative/parenthesis part. Keep in mind the code has to function whether the number is negative or positive.

推荐答案

http://www.php.net/manual/zh/function.money-format.php

echo money_format('%(n', '-44.00');

这篇关于是否有PHP函数可以将货币金额格式化为会计格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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