money_format - 负数

时间:2012-09-14 17:39:52

标签: php money-format

我收到了以下代码

#   On va convertir en somme monétaire
#   We convert our integer into a way to read money
$Vars['Income']     = money_format('%.2n', $Income);
$Vars['Spending']   = money_format('%.2n', $Spending);

#   On va calculer ce qui reste à dépenser
#   We do the math to know how much we can spend until the end of the month
$Vars['Remaining']  = money_format('%.2n', $Income - $Spending);

如果$Income - $Spending为负数(低于0),则收入低于支出。好的。我正在使用我的语言环境,法语(加拿大),负数的结果是(X,XX $)。

没有 - 符号对我来说没有意义所以我希望能够输出-0.00 $而不是(0.00 $)的数字。

示例我的收入是75.00 $,我的支出是100.00 $。我花了25美元,然后我就这样剩下的钱会输出(25.00美元),但我想要-25.00美元。

我确实尝试添加(或+但我不明白。

由于

更新:Picture

enter image description here

1 个答案:

答案 0 :(得分:5)

money_format的格式字符串有点令人困惑。你想要的是:

money_format('%+.2n', $Income - $Spending);
相关问题