在美分价格上加税的问题

发布于 2025-01-10 22:15:04 字数 359 浏览 2 评论 0原文

我有一个问题,我需要 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

檐上三寸雪 2025-01-17 22:15:04

尝试使用
圆形(4.96754,2)。这应该返回带 2 个小数点的数字。

Try using
round(4.96754,2). This should return you the number with 2 decimal points.

橘和柠 2025-01-17 22:15:04

有几个选项,现在发生的是返回一个浮点数。

一种方法是返回一个字符串,这些函数可以做到这一点

number_format 

https:// /www.php.net/manual/en/function.number-format.php

sprintf 

https://www.php.net/manual/en/function.sprintf.php

请记住您希望如何处理舍入,因为 number_format 也会对数字进行舍入。您可能对舍入有特定要求。

round 

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

number_format 

https://www.php.net/manual/en/function.number-format.php

sprintf 

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.

round 

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文