【问题标题】:Square Rounding Error (Banker's Rounding)平方舍入误差(银行家舍入)
【发布时间】:2020-06-14 21:25:05
【问题描述】:

我收到一个来自 square 的错误提示

{"errors": [{"code": "BAD_REQUEST","detail": "The total of the requested payments does not match the total of the sale order.","category": "INVALID_REQUEST_ERROR"}]}

商品是3.00,税是9.5%,我们的应用费是3%。

在我这边我发送过来

3.00
+ 0.29 (0.095 * 3.00 = 28.5 rounded up)
+ 0.09
______
  3.38

我可以清楚地看到这是我在请求中发送的金额,如果商品的价格为 2.99 或 3.01,它可以工作。当 Square 响应创建订单时,它返回 0.28 美元作为税额,这不是银行家的四舍五入。在这种情况下,我最好假设 Square 不会修复此错误,我应该四舍五入税收?

来自订单端点的响应:

{"order": {"id": "gMTUBc5FrYvLzkoNv6xOYfkLtkUZY","location_id": "RE7KBN4EGW4KT","line_items": [{"uid": "Z3mT3QHmkk4SPCkbrSW5MB","catalog_object_id": "NN5CHF66YK6MUGXG3BNWF6X5","quantity": "1","name": "Steamer","variation_name": "Regular","base_price_money": {"amount": 300,"currency": "USD"},"taxes": [{"uid": "rQurMfiksaO3xTaMqWdb1C","catalog_object_id": "YSI7WUNXGGSJRQEQ4QEQYK5G","name": "Sales Tax","percentage": "9.5","type": "ADDITIVE","applied_money": {"amount": 28,"currency": "USD"},"scope": "LINE_ITEM"}],"gross_sales_money": {"amount": 300,"currency": "USD"},"total_tax_money": {"amount": 28,"currency": "USD"},"total_discount_money": {"amount": 0,"currency": "USD"},"total_money": {"amount": 328,"currency": "USD"},"variation_total_price_money": {"amount": 300,"currency": "USD"},"applied_taxes": [{"uid": "rQurMfiksaO3xTaMqWdb1C","tax_uid": "rQurMfiksaO3xTaMqWdb1C","applied_money": {"amount": 28,"currency": "USD"}}]}],"taxes": [{"uid": "rQurMfiksaO3xTaMqWdb1C","catalog_object_id": "YSI7WUNXGGSJRQEQ4QEQYK5G","name": "Sales Tax","percentage": "9.5","type": "ADDITIVE","applied_money": {"amount": 28,"currency": "USD"},"scope": "LINE_ITEM"}],"fulfillments": [{"uid": "jJtsXtwaWfjJBIpbe7wkk","type": "PICKUP","state": "PROPOSED","pickup_details": {"pickup_at": "2020-06-14T20:58:09.257Z","recipient": {"display_name": "Table: #1"}}}],"created_at": "2020-06-14T20:43:09.731Z","updated_at": "2020-06-14T20:43:09.731Z","state": "OPEN","version": 1,"total_tax_money": {"amount": 28,"currency": "USD"},"total_discount_money": {"amount": 0,"currency": "USD"},"total_tip_money": {"amount": 0,"currency": "USD"},"total_money": {"amount": 337,"currency": "USD"},"service_charges": [{"uid": "2lD47tU2idwjyOpydkfrtB","name": "Service Fee","amount_money": {"amount": 9,"currency": "USD"},"applied_money": {"amount": 9,"currency": "USD"},"calculation_phase": "SUBTOTAL_PHASE","taxable": false,"total_money": {"amount": 9,"currency": "USD"},"total_tax_money": {"amount": 0,"currency": "USD"}}],"total_service_charge_money": {"amount": 9,"currency": "USD"},"net_amounts": {"total_money": {"amount": 337,"currency": "USD"},"tax_money": {"amount": 28,"currency": "USD"},"discount_money": {"amount": 0,"currency": "USD"},"tip_money": {"amount": 0,"currency": "USD"},"service_charge_money": {"amount": 9,"currency": "USD"}},"source": {"name": "Table: #1"}}}

【问题讨论】:

    标签: square-connect square


    【解决方案1】:

    仅当结束数字在两个数字之间等距时才适用银行家的四舍五入(在本例中为.05)。

    在你的例子中:

    3.00
    + 0.28 (0.095 * 3.00 = 0.285 which according to Banker's rounding, rounds to the closest even number, so this would be 0.28)
    + 0.09
    _______
      3.37
    

    在你的另一个例子中(3.01):

    3.01
    + 0.29 (0.095 * 3.01 = 0.28595 which would round to 0.286 and then use normal rounding, since it doesn't end in 5, to be 0.29)
    + 0.09
    ______
      3.39
    

    【讨论】:

    • 非常感谢您澄清您将四舍五入到最接近的偶数作为抢七!你救了我几个小时的头痛
    猜你喜欢
    • 2021-11-07
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多