平方舍入误差(银行家舍入)



我收到来自正方形的错误,上面写着

{"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"}}}

Banker 的舍入仅适用于两个数字之间的结束数字等距(在本例中为.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

最新更新