首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何舍入总价,无小数点显示?

问如何舍入总价,无小数点显示?
EN

Drupal用户
提问于 2020-09-11 12:18:54
回答 1查看 174关注 0票数 0

我需要数小数位(税,促销,费用.),但总价格必须在数学上四舍五入,没有小数。

示例:2 x product1 CZK 424.00 1 x Product2 CZK 408.00

CZK 832.00船运CZK 99.00折扣CZK -41.60 10%增值税71.86 21%增值税17.18 -Total CZK 889.40-删除圆角CZK - 0.60不需要显示总计CZK 889.00

EN

回答 1

Drupal用户

发布于 2020-09-11 14:22:45

这解决了我的问题:https://www.drupal.org/project/commerce/issues/3076196

my模块:

roundingmodule.info

代码语言:javascript
复制
name: Commerce rounding module.
type: module
description: Rounding.
core: 8.x
package: Custom

roundingmodule.services.yml

代码语言:javascript
复制
services:
  roundingmodule.rounding_order_processor:
    class: Drupal\roundingmodule\RoundingOrderProcessor
    tags:
      - { name: commerce_order.order_processor, priority: -10 }

roundingmodule.commerce_adjustment_types.yml

代码语言:javascript
复制
rounding:
  label: 'Rounding'
  singular_label: 'rounding adjustment'
  plural_label: 'rounding adjustments'
  has_ui: true
  weight: 20

src/RoundingOrderProcessor.php

代码语言:javascript
复制
    getTotalPrice();
      $rounded_total = $rounder->round($order_total->divide(100))->multiply(100);
      $difference = $rounded_total->subtract($order_total);

      $order->addAdjustment(new Adjustment([
        'type' => 'rounding',
        'label' => 'Rounding',
        'amount' => $difference,
      ]));
  }

}
票数 1
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/296651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档