条纹结帐价格错误-无效的整数 [英] Stripe Checkout Price error - Invalid Integer

查看:53
本文介绍了条纹结帐价格错误-无效的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Stripe帐户,正在使用测试API密钥。

I have a stripe account and am using the test API keys.

我创建了一个包含以下信息的计划-

I have created a Plan with following info -

{
  "amount": 995, 
  "created": 1418800758, 
  "currency": "usd", 
  "id": "c06e1791-1c6a-45fe-9c26-8f0c07dda967", 
  "interval": "month", 
  "interval_count": 1, 
  "livemode": false, 
  "metadata": {}, 
  "name": "Pro2", 
  "object": "plan", 
  "statement_description": null, 
  "statement_descriptor": null, 
  "trial_period_days": null
}

我是在我的项目中使用checkout.js。
填完所有数据,然后单击上述计划的付款时,会引发错误 Invalid Integer 994.999999999。

I'm using checkout.js in my project. Once all the data is filled and we click on pay for the above plan, it raises an error 'Invalid Integer 994.999999999'.

不会引发此错误我尝试过的$ 9.94,$ 9.96,$ 29.95和其他值。

This error is not raised for the $9.94, $9.96, $29.95 and other values tried by me.

这是结帐错误还是与我的设置有关?

Is this a checkout bug or something to do with my settings ??

错误的屏幕截图-

jsfiddle重现错误- http://jsfiddle.net/f30z9uc6/2/

jsfiddle reproducing the error - http://jsfiddle.net/f30z9uc6/2/

推荐答案

这里的问题是浮点错误在Javascript中。如果您查看此 jsfiddle 的更新版本,您将看到正在发生的事情以及如何解决它。您需要对计算结果进行四舍五入,以确保最终得到一个整数:

The problem here is a floating point error in Javascript. If you look at this updated version of your jsfiddle you'll see what's happening and how I fixed it. You need to round the result of your calculation to ensure you end up with an integer:

var amount = Math.round(9.95*100); // gives 995

要了解有关Javascript和浮点算法的更多信息,您应该查看浮点指南

To read more about Javascript and floating point arithmetic you should look into The Floating-Point Guide

这篇关于条纹结帐价格错误-无效的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆