Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 方形API截断价格?_Node.js_Square Connect - Fatal编程技术网

Node.js 方形API截断价格?

Node.js 方形API截断价格?,node.js,square-connect,Node.js,Square Connect,我正在使用square connect库,在创建项目时,我的价格被截断。例如,如果我将我的物品价格设置为123.13,结果是1.23 下面是我的代码示例: squareRouter.post('/item', function(req, res){ var item = req.body.item; console.log(item); square.api('/me/items', 'POST', item, function(err, resp){ data_handler(err,

我正在使用square connect库,在创建项目时,我的价格被截断。例如,如果我将我的物品价格设置为123.13,结果是1.23

下面是我的代码示例:

squareRouter.post('/item', function(req, res){
var item = req.body.item;
console.log(item);
square.api('/me/items', 'POST', item, function(err, resp){
    data_handler(err, resp, res);
  });
});
在控制台窗口中,以下是我的项目对象:

{ variations: { 
    pricing_type: 'FIXED_PRICING',
    price_money: { currency_code: 'USD', amount: 123.13 },
    name: 'Small' },
name: 'The Real test',
description: 'The price of this should be $123.13',
visibility: true,
available_online: true,
available_for_pickup: true }
但在我的仪表板上

我正在使用此处提供的方形连接npm模块:

我有一种丑陋的感觉,这是npm模块中的一个bug,不是我正在做的事情,但我很少发现这在实践中是真的。我是这里遗漏了什么,还是我需要在库中找到违反的代码并修复它?

指出当
货币\u code
美元时,那么
金额
是美分的数量,而不是美元的数量。因此,您应该使用
12313
而不是
123.13

例如,他们4.00美元的示例代码使用
400
表示
金额

  "variations": [
    {
      "name": "Small",
      "pricing_type": "FIXED_PRICING",
      "price_money": {
        "currency_code": "USD",
        "amount": 400
      }
    }
  ]

考虑到他们指定单位为美元,这很奇怪。它应该是USC。API使用美分来避免处理浮点数时可能出现的舍入错误。这实际上是金融软件中相当普遍的做法。