在美分价格上加税的问题
我有一个问题,我需要 11.90 而不是给我的 11.9。现在的问题是我应该如何做到这一点。如果我现在将价值 1000 美元的美分货币交出来,那就是 10.00 欧元,但一旦我加税,就需要 10.9 美元,但价格约为 10.90 美元。
if (! function_exists('get_tax_amount')) {
function get_tax_amount(Money $money)
{
return $money->getAmount() * 1.19 / 100;
}
}
当我不做 * 1.19 / 100 时,我得到“1000”;但对于税费,我需要 *1.19 / 100。
我能做什么?
I have the problem that I need 11.90 instead of 11.9 which is given to me. Now the question is how I should do that. if I now as $money a cents value like 1000 hand over it is 10.00€ well but as soon as I add taxes on it are 10.9 need but at something like 10.90.
if (! function_exists('get_tax_amount')) {
function get_tax_amount(Money $money)
{
return $money->getAmount() * 1.19 / 100;
}
}
i get a "1000" when i dont make * 1.19 / 100; but for tax i need that *1.19 / 100.
What can i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
圆形(4.96754,2)
。这应该返回带 2 个小数点的数字。Try using
round(4.96754,2)
. This should return you the number with 2 decimal points.有几个选项,现在发生的是返回一个浮点数。
一种方法是返回一个字符串,这些函数可以做到这一点
https:// /www.php.net/manual/en/function.number-format.php
https://www.php.net/manual/en/function.sprintf.php
请记住您希望如何处理舍入,因为
number_format
也会对数字进行舍入。您可能对舍入有特定要求。https://www.php.net/manual/en/function.round。 php
您还可以尝试使用 bc math 来处理您的计算
https://www.php.net/manual/en/book.bc.php
There are a few options, what is happening now is it is returning a float.
One way is to return a string, these functions can do that
https://www.php.net/manual/en/function.number-format.php
https://www.php.net/manual/en/function.sprintf.php
Keep in mind how you want to handle rounding, as
number_format
will round the number too. You may have specific requirements for rounding.https://www.php.net/manual/en/function.round.php
You could also try using bc math to handle your calcs
https://www.php.net/manual/en/book.bc.php