在 oscommerce 中转换后将价格四舍五入到最接近的 5

发布于 2024-08-30 23:31:09 字数 428 浏览 3 评论 0原文

与 oscommerce 中的价格相关的转换问题:

我需要自定义货币转换,将美元价格四舍五入到最接近的 5 美元,以避免价格显示为愚蠢的价格,例如 263 美元。

我正在尝试转换为 int 并舍入以下行:(

$curr->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']));

由于某种原因,价格显示为字符串,我猜测包括货币符号)

但是运气不佳。

有谁知道根转换发生在哪里,因为当它是原始整数时,我可能更容易从那里进行 round() 或 ceil()

或者关于如何舍入转换的任何其他想法?

感谢

里斯·托马斯的任何帮助

A conversion question relating to prices in oscommerce:

I am needing for a custom currency conversion to round the USD prices up to the nearest 5$ to avoid prices being displayed at silly prices such as $263.

I am trying to convert to an int and round the following line :

$curr->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']));

( as for some reason the price is displayed as a string, im guessing to include the currency sign)

However not having much luck.

Does anybody know where the root conversion takes place as it might be easier for me to round() or ceil() from there when it is a raw integer

Or any other ideas of how I can round the conversion?

Thanks for any help

Rhys Thomas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

余罪 2024-09-06 23:31:09

为了将浮点四舍五入到最接近的数字,我使用这样的方法。这可能会提供一些线索:

    // Rounds X to the nearest Y
    private double round(double x, double y)
    {
        return Math.Floor(x / y + 0.5) * y;
    }

For rounding floating points to a nearest number I use a method like this. This might give some clue:

    // Rounds X to the nearest Y
    private double round(double x, double y)
    {
        return Math.Floor(x / y + 0.5) * y;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文