【发布时间】:2024-01-20 06:51:02
【问题描述】:
我在 PHP/MySQL 中使用 "number_format" 函数来表示 money" 属性。
属性本身存储在我的数据库中。
Select account_balance from my_table where login = 'xxxxxx';
$correct_account_balance = number_format($account_balance,
['my_balance'],2); }
换句话说:表示“2”会在小数点后添加两个额外的数字,如下:10.00(例如)
此代码运行良好............除了一个小问题:如果小数点后的金额末尾有一个零,它不会显示!
例如:如果金额是 10 美元和 35 美分,它会正确显示:10.35
但是,如果金额为 10 美元和 30 美分,则显示为:10.3(而不是:10.30)
原因是:在我使用“number_format”函数转换之后,我的程序还会对 account_balance 执行算术运算。
例如:
$correct_account_balance -= 0.25 (this will subtract 0.25 each time the program is executed)
这就是为什么在实际金额末尾有一个“零”(例如:10.30)时,它会显示为:10.3
有没有办法解决这个问题? Google 似乎不知道;
【问题讨论】:
标签: php mysql number-formatting money-format