php - 由于税收,WooCommerce 中的四舍五入问题
问题描述
我添加了不含税的 WooCommerce 产品价格。
我的客户给我发了一份包含税的产品价格清单。加税后,产品需要以 65.25 欧元的价格出售。
现在的问题是它在计算税后显示为 65,24 欧元。我希望价格为 65,20 欧元或 65,25 欧元,因为它看起来更干净。是否有任何功能只会创建 5 美分的步长。
我找到了这个功能,但这仅适用于购物车中的总价。我希望每个产品都能做到这一点
add_filter( 'woocommerce_calculated_total', 'my_custom_roundoff' );
function my_custom_roundoff( $total ) {
$round_num = round($total / 0.05) * 0.05;
$total = number_format($round_num, 2); // this is required for showing zero in the last decimal
return $total;
}
解决方案
推荐阅读
- java - BigDecimal 添加函数显示值不正确
- reactjs - default.props 的覆盖是如何发生的
- mysql - 使用 ON DUPLICATE KEY UPDATE 在父表上检测到重复项时如何更新子表
- database - 如何确定事务是否可冲突序列化?
- c++ - DLL 注入适用于某些进程,但不适用于其他进程
- python - 使用属性装饰器时类属性不更新
- reactjs - 从 axios 获得空响应
- python - 我如何使用 2 个 numpy 数组作为去噪自编码器的数据集,并将它们进一步拆分为训练集和测试集
- parsing - 根据我的 BASIC 语法正确匹配一组标记
- java - gridview 使用小部件nestedscrollview xml